码迷,mamicode.com
首页 > 系统相关 > 详细

Shell script之How to write

时间:2015-07-10 20:45:15      阅读:152      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!