Excerpt from: Abs_guide
: http://www.tldp.org/LDP/abs/abs-guide.pdf
The meaning of shell variable $#,[email protected],$0,$1,$2 in Linux is explained: Variable Description: $$ The PID of the shell itself (ProcessID) $! PID of the Shell's last running background process $? End code of the last Run command (return value) $- Flag at a glance using the SET command $* All parameter lists. such as "$*" in the Case of "" ", in the form of" $ $ ... $n "output all parameters. [Email protected] All parameter lists. such as "[email protected]" with "" "in the case, with" $ "" $ "... All parameters are output in the form "$n". $# Number of arguments added to the shell $ The name of the shell itself $1~ $n Each parameter value added to the shell. $ $ is the 1th parameter, and the $ = is the 2nd parameter .... |
Example:
1 #!/bin/bash 2 # 3 printf "The complete list is %s\n""$$" 4 printf "The complete list is %s\n""$!" 5 printf "The complete list is %s\n""$?" 6 printf "The complete list is %s\n""$*" 7 printf "The complete list is %s\n""[email protected]" 8 printf "The complete list is %s\n""$#" 9 printf "The complete list is %s\n" "$0"10 printf "The complete list is %s\n""$1"11 printf "The complete list is %s\n""$2 |
Results:
[[email protected] ~]$ bash params.sh 123456 QQThe complete list is24249The complete list isThe complete list is0The complete list is123456 QQThe complete list is123456The complete list isQQThe complete list is2The complete list isparams.shThe complete list is123456The complete list isQQ |
Linux shell variable $#,[email protected], $0,$1,$2 meaning explanation