########################
Summary of several special shell variables:
########################
######################################## ####################
#
# Http://hi.baidu.com/xece/modify/blog/75327e382149dae23b87ce5a
######################################## ####################
Special shell variables:
$0 get the name of the currently executed shell script
$ N obtain the nth parameter value of the currently executed shell script, n = 1 .. 9
$ * Get all parameters of the current shell "$1 $2 $3... Note the difference with $ #
$ # Obtain the total number of parameters in the Current Shell Command Line
$ Obtain the current shell process ID (PID)
$! PID used to execute the previous command
$? Obtain the returned value of the previous Command executed (0 indicates success, and non-zero indicates failure)
$ @ All parameters of this program "$1" "$2" "$3" "…"
Example ):
[Ryan @ etiantian test] # Cat etiantian. Sh
Echo '$0 get the name of the currently executed shell script:' $0
Echo '$ n get the nth parameter value of the currently executed shell script, n = 1 .. 9: ''$ 1' = $ 1' $ 2' = $2 '\ $3 = $3 ″
Echo '$ * Get all parameters of the Current Shell' $1 $2 $3... Note the difference with $ #: '$ *
Echo '$ # obtain the total number of parameters in the current shell command line:' $ #
Echo '$ obtain the current shell process ID (PID):' $
Sleep 2 &
Echo '$! PID for executing the previous command: '$!
Echo '$? Obtain the returned value of the previous command: '$?
Echo '$ @ all parameters of this program "$1" "$2" "$3" "…" : '$ @
Script Execution results (carefully read ):
[Ryan @ etiantian test] # sh etiantian. Sh parameter 1 parameter 2 parameter 3
$0 get the name of the currently executed shell script: etiantian. Sh
$ N get the nth parameter value of the currently executed shell script, n = 1 .. 9: $1 = parameter 1 $2 = parameter 2 $3 = parameter 3
$ * Get all parameters of the current shell "$1 $2 $3... Note the difference with $ #: parameter 1 parameter 2 parameter 3
$ # Obtain the total number of parameters in the current shell command line: 3
$ Obtain the current shell process ID (PID): 2062
$! PID for executing the previous command: 2063
$? Obtain the returned value of the Last Command executed: 0
$ @ All parameters of this program "$1" "$2" "$3" "…" : Parameter 1 parameter 2 parameter 3
[Ryan @ etiantian test] # sh etiantian. Sh Ryan jeacen David
$0 get the name of the currently executed shell script: etiantian. Sh
$ N get the nth parameter value of the currently executed shell script, n = 1 .. 9: $1 = Ryan $2 = jeacen $3 = David
$ * Get all parameters of the current shell "$1 $2 $3... Note the difference with $ #: Ryan jeacen David
$ # Obtain the total number of parameters in the current shell command line: 3
$ Obtain the current shell process ID (PID): 2160
$! PID for executing the previous command: 2161
$? Obtain the returned value of the Last Command executed: 0
$ @ All parameters of this program "$1" "$2" "$3" "…" : Ryan jeacen David