shell中的位置参数和特殊参数

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的文件名

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值