標籤:
Write shell script:
1) Editor like vi or mcedi
2) Set execute permission for your script
chmod permission your-script-name
$ chmod +x your-script-name$ chmod 755 your-script-name
This will set read write execute(7) permission for owner, for group and other permission is read and execute only(5).
3) Execute script
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.
Example:
$ . foo
4) Practice
1 $ vi first2 #3 # My first shell script4 #5 clear6 echo "Knowledge is Power"
1 $ vi ginfo 2 # 3 # 4 # Script to print user information who currently login , current date & time 5 # 6 clear 7 echo "Hello $USER" 8 echo "Today is \c ";date 9 echo "Number of user login : \c" ; who | wc -l10 echo "Calendar"11 cal12 exit 0
Shell script之How to write