`

shell script

 
阅读更多
select r.name, count(p.id) from persons as p join rides as r on p.fav_ride_id = r.id group by r.id order by count(p.id) desc limit 2;

一整就用到
$PWD
$PATH
$HOME


The shell has variables to access arguments in the procedures, to define the environment and the like. Shell variables are:

$1        # argument ($0..$9, $#)
PATH      # predefined symbol
mydir     # user defined symbol

Symbols are created using the = operator (no blanks allowed), thus:
mydir=`pwd`      # mydir keeps track of current working directory
The symbol mydir can be used to restore the current working directory, as shown below:
$ cd gks/work      # change working directory
$ mydir=`pwd`      # set symbol mydir
$ cd               # restore root directory
$ cd new           # move to new directory
$ cd $mydir        # return to previous directory
The command set lists all available symbols in the current session. Any variable is defined only in the current subshell, to make the variable global to any subshell use the export command as shown below.
Local definition of mydir:
$ mydir=`pwd`
$ echo $mydir   # prints the current directory (i.e. /u/code or the like)
$ sh            # run new shell
$ echo $mydir   # mydir is not defined at subshell
Global definition of mydir:
$ mydir=`pwd`; export mydir
$ echo $mydir   # prints value of current directory (i.e. /u/code ...)
$ sh            # run new shell
$ echo $mydir   # value of mydir is same as above (i.e. /u/code ...)
Predefined variables like PATH can be changed only at current shell level:
$ PATH=$PATH:/new
To change the variable in .profile and have it active the   (dot) command must be used:
$ . ./.profile
The command:
$ sh .profile
does not change the value of PATH as it is executed in a subshell, using . (dot) means use .profile as standard input so that the commands are really executed in the active shell.
In case some applications require to change the value of PATH during a session without modifying .profile, edit a file (ex. newp) containing a command as follows:

$ PATH=$PATH:/newdir
then type:
$ . ./newp

to set the new path value. In case you want to restore the default PATH, use:
$ cd
$ . ./.profile
to reset the .profile setup.
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics