Positional Parameters
A positional parameter is a parameter denoted by one or more digits, other than the single digit 0. Positional parameters are assigned from the shell's arguments when it is invoked, 。。。
位置参数是由一个或多个数字指代的参数,不包含数字0。当shell被调用的时候它把参数赋值给位置参数,。。。
Special Parameters
0
Expands to the name of the shell or shell script. This is set at shell initialization. If bash is invoked with a file of commands, $0 is set to the name of that file. If bash is started with the -c option, then $0 is set to the first argument after the string to be executed, if one is present. Otherwise, it is set to the file name used to invoke bash, as given by argument zero.
0(注意0是特殊参数,不是位置参数)
$0展开为shell或shell script的名字。它在shell初始化的时候设置。如果bash被调用的时候有一个命令文件参数,$0被设置为那个(脚本)文件的名字。如果bash被调用的时候带一个-c option,那么$0被设置为要被执行的字符串后的第一个参数,条件是起码有一个参数被提供。否则,它被设置为调用bash的文件名,如(bash的)参数0所示。
最后举一个实例:
[root@VM_0_11_centos script]# ls
aaa test.sh
[root@VM_0_11_centos script]# cat test.sh
ls $1
echo $0,$1
[root@VM_0_11_centos script]# bash test.sh "*.sh"
test.sh
test.sh,*.sh
$0被设置为那个(脚本)文件的名字
[root@VM_0_11_centos script]# bash -c 'echo $0' foo
foo
$0被设置为要被执行的字符串后的第一个参数
[root@VM_0_11_centos script]# bash -s "*.sh" <test.sh
test.sh
bash,*.sh
$0被设置为调用bash的文件名