首页 > 系统服务 > 详细

Shell script之How to write

时间:2015-07-10 20:43:37      阅读:272      评论:0      收藏:0      [点我收藏+]

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

 

Shell script之How to write

原文:http://www.cnblogs.com/mengdie/p/4637081.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!