Objectives
• Start a script with #!
• Put comments in a script
• Put commands in a script
• Change permissions on the script
• Execute a script
• Debug a script
Creating Shell Scripts
• Create a file using any text editor
• Put UNIX commands, user programs, or the names of
other scripts as commands in the file
• Save the file, and exit from the editor
$ vi firstscript.sh
$ cat firstscript.sh
#!/bin/sh
clear
echo "SCRIPT BEGINS"
echo "Hello $LOGNAME!"
echo
echo "Todays date and time: \c"
date
echo
mynum=21
myday="Monday"
echo "The value of mynum is $mynum"
echo "The value of myday is $myday"
echo
echo "SCRIPT FINISHED!!"
echo
Executing a Shell Script
• Give the script execute permission
• Execute the script as a command
• Create a subshell in which to execute the script
Executing firstscript.sh
$ cat firstscript.sh
#!/bin/sh
clear
echo "SCRIPT BEGINS"
echo "Hello $USER!"
echo
echo "Todays date and time: \c"
date
echo
mynum=21
myday="Monday"
echo "The value of mynum is $mynum"
echo "The value of myday is $myday"
echo
echo "SCRIPT FINISHED!!"
echo
Disclaimer
.........................................................................................................................................................
The all content are through my experiences, that i have learn in going through Studies and in building projects, some of were taken from some web sites, books and other sources, where i have visited and learn the concepts, I am very thankful to them for having those valuable things, which make me more efficient, and i have added those all in my experience. If any of these content violets copyrights, please contact me i will try to resolve and will do the needful assistance. Thank you all very much.
..........................................................................................................................................................
..........................................................................................................................................................
..........................................................................................................................................................
No comments:
Post a Comment