Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有多个长选项的bash_Bash - Fatal编程技术网

具有多个长选项的bash

具有多个长选项的bash,bash,Bash,我有一个bash脚本,我不想阅读bashrc或bash概要文件。所以我试了一下: #!/bin/bash --norc --noprofile echo ran 它给了我这个错误: > ./tst.sh /bin/bash: --norc --noprofile: invalid option Usage: /bin/bash [GNU long option] [option] ... GNU long options: --debug --debugger

我有一个bash脚本,我不想阅读bashrc或bash概要文件。所以我试了一下:

#!/bin/bash --norc --noprofile
echo ran
它给了我这个错误:

> ./tst.sh 
/bin/bash: --norc --noprofile: invalid option
Usage:  /bin/bash [GNU long option] [option] ... 
GNU long options:
    --debug
    --debugger
    --dump-po-strings
    --dump-strings
    --help
    --init-file
    --login
    --noediting
    --noprofile
    --norc
    --posix
    --protected
    --rcfile
    --rpm-requires
    --restricted
    --verbose
    --version
    --wordexp

似乎我只能指定一个长选项,但我找不到记录在案的选项。--noprofile可能已经过时了,但我仍然很好奇为什么我不能指定多个长选项,关键是你最多可以在shebang行指定一个选项(它与长或短选项无关)

更准确地说,操作系统的
execve
功能会传递接下来的一切
#/bin/bash
作为bash的单个参数。这将产生与执行相同的结果

bash "--norc --noprofile"
这就产生了你的错误

正如评论(和)中的链接所指出的,这种行为是特定于操作系统的,其变化包括:

  • 将所有单词作为单个参数(您的案例)
  • 每一个单词都是一个独立的论点(你所期待的)
  • 仅将第一个单词作为单个参数
  • 没有争论

结论:在您的操作系统上,您不能在shebang行上为bash指定多个参数,即使可以,您也可能不应该指定,因为脚本在不支持多个shebang参数的操作系统上会失败。

shebang在
execve(2)
中有说明。ubuntuexecve手册页在这里:我在这两个页面中都没有看到任何东西可以解释为什么第二个arg是一个问题。我看到一行太长,但这似乎不是本例中的问题。