shell script '$' symbol with a meaning different from its representation will be different
Special identifier | meaning |
$0 | The current name of the script file |
$n | Arguments passed to the script or function. n is a number that represents the number of parameters. For example, the first parameter is $ 1, $ 2 is the second parameter |
$# | The number of arguments passed to the script or function |
$* | Passed to the script or function of all parameters |
$@ | Passed to the script or function of all parameters |
$? | The exit status of the previous command |
$$ | Shell current process ID |
$() | And `(backtick) command is used to replace the use of the same |
${} | Reference variables divided border |
Note: $ * and $ @ expressed passed to all parameters of the function or script, "included, are not to be double quotation marks (") "output of all parameters in the form of $ 1" "$ 2" ... "$ n" is. However, when they are in double quotes ( "") included, "$ *" resets all of the parameters as a whole, to "$ 1 $ 2 ... $ n" output in the form of all parameters; "separate $ @" will each parameter, All output parameters in the form of "$ 1" "$ 2" ... "$ n" of
#! /bin/bash echo "file name $0" echo "first param $1" echo "pid $$" echo "total num of param $#" echo "last status $?" echo "$@" echo "$*"
Execution ./1.sh hello mayuan
file name ./1.sh first param hello pid 142 total num of param 2 last status 0 hello mayuan hello mayuan