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.

$ . 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

  

 5) Feng - quickly go to specific directory by shell scripts

 1 #!/bin/bash
 2 # ----------------------------------------------------------------------------
 3 # quickly go to software development directory
 4 # ----------------------------------------------------------------------------
 5 
 6 if [ $# -eq 0 ]; then
 7     cd '01_Project/02_Projrct_Name/02_DIGITAL/01_src/software/embedded'
 8     # list all the software development directory
 9     ls
10 fi

 then in your Linux terminal enter

# dot(.) can execute command file at current directory
. software.sh

 

posted on 2015-07-10 19:25  mengdie  阅读(286)  评论(0编辑  收藏  举报