标签:
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 first 2 # 3 # My first shell script 4 # 5 clear 6 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 -l 10 echo "Calendar" 11 cal 12 exit 0
标签:
原文地址:http://www.cnblogs.com/mengdie/p/4637081.html