- Use any editor to write shell script.
- After writing shell script set execute permission for your script as follows:
$ chmod +x your-script-name
or
$ chmod 755 your-script-name
- Execute your script as;
$ bash your-script-name
$ sh your-script-name
$ ./your-script-name
- In the last syntax ./ means current directory.
- But only . (dot) means execute given command file in current shell without starting the new copy of shell as follows;
$ . your-script-name
Now you are ready to write first shell script that will print "Knowledge is Power" on screen. http://siber.cankaya.edu.tr/SystemsProgramming/cfiles/firstfirst
#
# My first shell script
#
clear
echo "Knowledge is Power"
After saving the above script, you can run the script as follows:
$ ./first
This will not run script since we have not set execute permission for our script first; to do this type command
$ chmod 755 first
$ ./first
- Script to print user information who currently login , current date and time.http://siber.cankaya.edu.tr/SystemsProgramming/cfiles/ginfoginfo
#
#Script to print user information who currently login , current date
# & time
#
clear
echo "Hello $USER"
echo -e "Today is \c ";date
echo -e "Number of user login : \c" ; who | wc -l
echo "Calendar"
cal
exit 0
At the end why statement exit 0 is used?