On 19/04/2020 12:27, Robert Elz wrote:
My first reading (my immediate impression) is that your interpretation A
is what is intended, and only a return command executing directly from the
trap action itself, and not one in a function that happens to be called,
should be affected.   (And of course, the former is only specified if the
trap occurs while running a function or dot script).

My reading was that interpretation B must be what is intended, which is why I had modified my shell, a fork of dash, to change dash's A behaviour to B in late 2018. My reasoning for that is that the description of the return commanhd ("When return is executed in a trap action, the last command is considered to be the command that executed immediately preceding the trap action.") is identical to that of the exit command ("When exit is executed in a trap action, the last command is considered to be the command that executed immediately preceding the trap action."), and for the exit command, almost all shells, including dash, are in agreement that it applies even when the exit command is invoked indirectly. If different behaviour is intended for the exit and return commands, but identical wording is used for both, that must surely be a defect in the standard.

Cheers,
Harald van Dijk

Reply via email to