On 29/11/2018 15:02, Martijn Dekker wrote:
Op 29-11-18 om 15:48 schreef Herbert Xu:
The problem is that in evalsubshell we end up in exitshell again
which restores the old exit status. So we need to come up with
a way to differentiate the exitshell from the original shell vs.
a subshell.
Isn't it much simpler than that? Upon forking a subshell, traps are
reset, so it would make sense that any flag that says "we are currently
in the process of executing a trap" is also reset.
There's more than just trap status that should be reset in subshells.
for x in a b
do
(
for y in c d
do
break 2
done
echo $x
)
done
I expect this to print "a" and "b", possibly accompanied by some error
messages from break. Instead, dash (like ksh, bosh and zsh) remembers
there's an outer loop and tries to break out of that from within the
subshell, which of course doesn't work. It doesn't print anything.
It looks like the child process should call exitreset(), which fixes
this and will also set savestatus to -1 -- except for exitreset()'s
(correct) behaviour of also closing redirections.