On 29/11/2018 20:28, Martijn Dekker wrote:
Op 29-11-18 om 20:56 schreef Harald van Dijk:
That's part of it, but not the whole story. Herbert Xu's comment about
exitshell() was right, that is still a problem. A testcase for this is
trap '(true) || echo bug' EXIT
Yes. Thanks. I hadn't thought about that.
The test case above is not quite complete. It needs to make sure the
exit status is non-zero before executing the trap:
$ src/dash -c "trap '(true) || echo bug' EXIT; false"
bug
I had intended it as a testcase for dash with your change applied, in
which case it fails even without making sure of that since you hit
_exit(savestatus) with savestatus reset to -1, but I like that it's so
easy to modify to also fail on unpatched dash, so thanks for that.
By the way, my change has an unintended but possibly acceptable side effect:
trap '(trap "echo exit" EXIT; :)' EXIT
This prints nothing with current dash, but prints "exit" with my change.
It also prints "exit" in ksh, mksh, posh, and bosh.
- Martijn