4.1.5(1)的bash(1)手册页说:
-- If no arguments follow this option, then the positional
parameters are unset. Otherwise, the positional parame‐
ters are set to the args, even if some of them begin
with a -.
- Signal the end of options, cause all remaining args to
be assigned to the positional parameters. The -x and -v
options are turned off. If there are no args, the posi‐
tional parameters remain unchanged.
第一个区别是 – 或 – 之后没有参数.对于前者,现有的位置参数将保持不变.对于后者,将清除位置参数.
所以设置 – 清除位置参数和设置 – 是一个无操作.
-v和-x设置可以通过set修改 – ….所以,如果你设置-v打开(导致shell在读取时打印输入行),它将被设置关闭 – …命令.设置 – …将保持不变.
set -x更常见的是set -v在set -x中经常用于调试脚本以确切地查看正在运行的命令.通常在调试shell脚本时,您可以使用bash -x< script>运行它.知道set – …关闭-x,你可能想要使用set – …,因为将-x作为另一个命令的副作用关闭会非常意外.