linux中shell變量$#,$@,$0,$1,$2的含義解釋: 變量說明: $$ Shell自己的PID(ProcessID) $! Shell最後運行的後臺Process的PID $? 最後運行的命令的結束代碼(返回值) $- 使用Set命令設定的Flag一覽 $* 全部參數列表。如"$*"用「"」括起來的狀況、以"$1 $2 … $n"的形式輸出全部參數。 $@ 全部參數列表。如"$@"用「"」括起來的狀況、以"$1" "$2" … "$n" 的形式輸出全部參數。 $# 添加到Shell的參數個數 $0 Shell自己的文件名 $1~$n 添加到Shell的各參數值。$1是第1參數、$2是第2參數…。 |
示例:linux
#/bin/bash printf "The complete list is %s\n" "$$" printf "The complete list is %s\n" "$!" printf "The complete list is %s\n" "$?" printf "The complete list is %s\n" "$*" printf "The complete list IS %s\n" $* printf "The complete list is %s\n" "$@" printf "The complete list Is %s\n" $@ printf "The complete list is %s\n" "$#" printf "The complete list is %s\n" "$0" printf "The complete list is %s\n" "$1" printf "The complete list is %s\n" "$2" |
結果:shell
[root@bogon bin]# bash ceshi.sh 123456 QQ The complete list is 14739 The complete list is The complete list is 0 The complete list is 123456 QQ The complete list IS 123456 The complete list IS QQ The complete list is 123456 The complete list is QQ The complete list Is 123456 The complete list Is QQ The complete list is 2 The complete list is ceshi.sh The complete list is 123456 The complete list is QQ |
摘抄自:ABS_GUIDEbash
下載地址:http://www.tldp.org/LDP/abs/abs-guide.pdfide