bash中`set -o`选项的预期有效排序是什么? `histexpand`是否特朗普`posix`?

时间:2014-02-01 08:52:45

标签: bash set posix standards sh

我试图在几个小时前回答一个问题,我认为这个问题在bash POSIX mode中揭示了一个有点模糊的错误。我匆匆而且激烈地告诉我不是这样。这个矛盾的答案,明确地说这是一个错误,被选为正确的答案。

所以我一直在梳理bash文档,而且我仍然会得到非常相同的印象,所以我想我应该问。

我的(涉嫌)错误:

set -o histexpand(通常是隐含的)
set -o posix
echo "#!/"

应该回复#!/。 (它在任何其他shell中都有)。但是在bash中反而是 打印到标准输出

!/: event not found

然后返回0.

所以在我看来,bash的隐式set -o histexpand在极少数情况下违反了POSIX标准,并且不会让set -o posix让路。

set -o posix的文档内容为:

Change the behavior of Bash where the default operation differs from the POSIX standard ... This is intended to make Bash behave as a strict superset of that standard.

而且我一直认为这意味着这个选项在它们相互矛盾时应该取代其他set选项? 这似乎也不是48 enumerated differences之一。

情况不是这样吗?我错过了什么?

2 个答案:

答案 0 :(得分:5)

Bash POSIX Mode reference 期待您所看到的行为 - 它没有在该列表的任何位置说明历史数字(PS1和{{之外) 1}}扩展)将以PS2集的方式区别对待。此外,由于其他人说这不是一个错误,我猜“超集”的含义是,只要没有特定于Bash的设置,shell将按照POSIX标准运行。

有趣的是,即使您运行posix,默认情况下也会启用某些特定于Bash的设置:

bash --noprofile --norc --posix

POSIX Shell Command Language documentation中没有提到这些内容(我先在bash-4.2$ set -o | grep 'on$' braceexpand on emacs on hashall on histexpand on history on interactive-comments on monitor on posix on 中查找了他们的缩写),而 man bash未在任何地方提及

答案 1 :(得分:-1)

从“!”关闭历史记录扩展令牌,使用

set +o histexpand

你有一个“-o” 与直觉相反,“+ o”将他的声音关闭。