$0 $1 表示第几个参数,在awk中以$1开始计
$# 参数个数
$* 所有位置参数作为一个单词
$@ 与$*同义,但每一个参数都是一个独立的“引用字符串”,推荐使用$@
$_ 之前执行的命令的最后一个参数
$? 命令、函数或者脚本本身的退出状态
$$ 脚本自身的PID,可用于构造一个“unique”的临时文件名
示例:
test.sh:
echo "the total number of parameters is $#"echo "the name of shell file is $0"echo "the total parameters using \$*: $*"echo "the total parameters using \$@: $@"echo "arg in \"\$*\""for arg in "$*"do echo $argdoneecho "arg in \"\$@\""for arg in "$@"do echo $argdoneecho "the last parameter is $_"echo "the shell pid id $$"
运行:chmod 777 test.sh ; ./test.sh one two three
输出:
the total number of parameters is 3the name of shell file is ./test.shthe total parameters using $*: one twothreethe total parameters using $@: one twothreearg in "$*"one two threearg in "$@"onetwothreethe last parameter is threetheshell pid id 27635