Normally shells are interactive. It means shell accept command from you (via keyboard) and execute them. But if you use command one by one (sequence of 'n' number of commands) , the you can store this sequence of command to text file and tell the shell to execute this text file instead of entering the commands. This is know as shell script.
- Shell script can take input from user, file and output them on screen.
- Useful to create our own commands.
- Save lots of time.
- To automate some task of day today life.
- System Administration part can be also automated.

Example No1
$ vi first
#
# My first shell script
#
clear
echo "Knowledge is Power"
Example No2
$ vi ginfo
#
#
# Script to print user information who currently login , current date & time
#
clear
echo "Hello $USER"
echo "Today is \c ";date
echo "Number of user login : \c" ; who | wc -l
echo "Calendar"
cal
exit 0
After writing ur shell script(s), set execute permission by typing $
chmod permission your-script-name ex. $ chmod 755 first
$ ./your-script-name ex. ./first
NOTE: The syntax ./ means current directory, But only . (dot) means execute given command file in current shell without starting the new copy of shell. The syntax for . (dot) command is $
. command-name ex. $ . first
NOTE: Read the "VI editor" tutorial and "Linux commands" tutorial in this section if not yet.
No comments:
Post a Comment