假设我想像这样通过 Bash 运行一个命令:
/bin/bash -c "ls -l"
Run Code Online (Sandbox Code Playgroud)
根据 Bash 手册页,我也可以这样运行它:
# don't process arguments after this one
# | pass all unprocessed arguments to command
# | |
# V V
/bin/bash -c ls -- -l
Run Code Online (Sandbox Code Playgroud)
除了它似乎不起作用(似乎被忽略了)。我做错了什么,还是我解释的手册页错误?
来自 man 的相关引用:
如果存在 -c 选项,则从字符串中读取命令。如果字符串后面有参数,则将它们分配给位置参数,从 $0 开始。
和
A -- 表示选项结束并禁用进一步的选项处理。-- 之后的任何参数都被视为文件名和参数。