Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the intended effective ordering of `set -o` options in bash? Does `histexpand` trump `posix`?

I attempted to answer a question a couple hours ago which I believed revealed a somewhat obscure bug in bash POSIX mode. I was hastily and vehemently told this was not so. The contradicting answer, which explicitly says this is not a bug, was selected as the correct answer.

So I've been combing over the bash documentation, and I'm still coming away with very much the same impression, so I thought I should ask.

My (alleged) bug:

set -o histexpand (which is typically implicit)
set -o posix
echo "#!/"

Should, well, echo #!/. (It does in any other shell). But in bash it instead prints to standard output

!/: event not found

And then returns 0.

So it would seem to me that bash's implicit set -o histexpand is in rare cases in contravention of the POSIX standard, and does not make way for set -o posix.

The documentation for set -o posix reads:

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.

And I've always thought that this meant that this option should supersede other set options when they contradict? This doesn't appear to be one of the 48 enumerated differences either.

Is this not the case? What am I missing?

like image 994
Geoff Nixon Avatar asked Feb 01 '14 08:02

Geoff Nixon


1 Answers

From the Bash POSIX Mode reference I would expect the behaviour you're seeing - it doesn't say anywhere on that list that history numbers (outside of PS1 and PS2 expansions) will be treated differently with posix set. Also, since others said it was not a bug I guess the meaning of "superset" is that as long as no Bash-specific settings are in place the shell will behave according to the POSIX standard.

Interestingly, even if you run bash --noprofile --norc --posix some Bash-specific settings are on by default:

bash-4.2$ set -o | grep 'on$'
braceexpand     on
emacs           on
hashall         on
histexpand      on
history         on
interactive-comments    on
monitor         on
posix           on

None of these are mentioned in the POSIX Shell Command Language documentation (I looked up their shorthands in man bash first), and interactive-comments is not mentioned anywhere.

like image 137
l0b0 Avatar answered Nov 17 '22 16:11

l0b0