Shell中的一些特殊变量
shell中的一些特殊变量 shell中的特殊变量: $0 $* $@ $# $_ $$ $! $? #!/bin/bash testargs "$*" 在terminal窗口中执行: 这里有一个很有意思的问题,如果test.sh为如下的内容: #!/bin/bash testargs $* 再次执行有: 另,这些特殊的shell变量可以和perl中类似的变量作比较,不同哦!
shell或shell脚本的名字
以一对双引号给出参数列表
将各个参数分别加双引号返回
参数的个数
代表上一个命令的最后一个参数
代表所在命令的PID
代表最后执行的后台命令的PID
代表上一个命令执行后的退出状态
为了区别$*和$@编写如下test.sh脚本:
function testargs
{
echo "$# args"
}
testargs "$@"
unset -f testargs
xk@linux:~/work> ./test.sh -a -b /home
1 args
3 args
xk@linux:~/work>
function testargs
{
echo "$# args"
}
testargs $@
unset -f testargs
xk@linux:~/work> ./test.sh -a -b /home
3 args
3 args
xk@linux:~/work>