Op 01-12-18 om 11:39 schreef Harald van Dijk:
On 01/12/2018 08:45, Herbert Xu wrote:
Hmm, I think this breaks the following case which used to work:
dash -c 'trap "(:; exit) && echo BUG" EXIT; false'
I know this makes no sense but almost every other shell does it
this way.
"Almost every other shell"? In the shells I tested, other than dash,
it's evenly divided: four print nothing (bash, ksh, mksh, yash), four
print BUG (bosh, pdksh, posh, zsh). Which ones are you testing?
To me, the standard is unclear on what the output should be: if at the
time exit is executed, traps are reset, can what's being executed still
be considered a trap action?
The word 'reset' is not ambiguous. Resetting traps in a subshell means
that subshells forget all about the parent shell's traps, so the fact
that the parent shell that forked that subshell happens to be executing
a trap action is irrelevant to the behaviour of the subshell. Thus, the
'BUG' output is actually the correct one here.
As Herbert acknowledged, the alternative makes no sense. I think the
standard *is* clear. But even (or especially) if the standard is
unclear, blatantly illogical behaviour should be considered a bug.
It's a nice test case whatever the correct result.
Yes.
- M.