mksh: set -e interop with functions (possibly) wrong
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
mksh |
Fix Released
|
High
|
Thorsten Glaser |
Bug Description
POSIX set description says:
-e
When this option is on, if a simple command fails for any of the reasons listed in
compound list following a while, until, or if keyword, and is not a part of an AND or OR list,
and is not a pipeline preceded by the ! reserved word, then the shell shall immediately exit.
But all pdksh-derived shells including posh do:
tg@blau:~ $ mksh -c 'set -e; bla() { [ -x /nonexistant ] && /nonexistant; }; bla; echo x$?'; echo y$?
x1
y0
Instead of:
tg@freewrt:~ $ ksh93 -c 'set -e; bla() { [ -x /nonexistant ] && /nonexistant; }; bla; echo x$?'; echo y$?
y1
I believe mksh may be too lax returning an error here. Discovered while helping Natureshadow with script corner cases caused by Debian’s damned “set -e” requirement. This should not affect BSD make negatively.
Hm, actually, the turning point is here:
tg@blau:~ $ mksh-R36b -c 'set -e; bla() { [ -x /nonexistant ] && /nonexistant; }; bla; echo x$?'; echo y$?
y1
tg@blau:~ $ mksh-R37 -c 'set -e; bla() { [ -x /nonexistant ] && /nonexistant; }; bla; echo x$?'; echo y$?
x1
y0
This means oksh may not be affected.
Considering this is a regression between R36b and R37, and POSIX (to me) looks like this is wrong, raising severity to important.