Sunday, June 28, 2015

How to write shell script - example

How to write shell script - example


############################################################
#!/bin/sh   #
# name_of_the_Script.sh -  write what it does.   #
#   #
# Auther Name or E-mail - Thu Jan 26 09:44:45 EST 2012   #
#   #
#   #
############################################################

Body of the script

############################################################
# EOF: name_of_the_Script.sh


Step by step Guide,

1. Just write the header and footer section.

#!/bin/sh
# file_name.sh
#
# Auther: Kanchha, Date
#


############################
# EOF: file_name.sh


2. Now, Fill with the body part.

#!/bin/sh
# file_name.sh
#
# Auther: Kanchha, Date
# Modified: By Sam, what features added and possibly why

# Body of the script
# ------------------

# Listing users home directory.
echo " Listing files on my home directory ...."
echo "-------------------------"

#ls -l ~sam
ls -l /export/home/sam
x=`echo $?`
# Record the exist status of the script
#
if [ $x -eq 0 ]; then
echo "Listing successful."
elif [ $x -eq 1 ]; then
echo "Failed to list the directory content"
else
echo "Check the directory location"
fi

############################
# EOF: file_name.sh

No comments:

Post a Comment