The wording can be construed the intent is the EXIT trap is always expected to 
be called, with a SIGEXIT delivered to the context of the subshell and not the 
parent, and otherwise to the parent for performing the trap in its context and 
terminating the parent. While a subshell context is created as a duplicate of 
the parent, by the time an exit call is processed it may differ significantly 
and so should be its own target; it is not on the parent to attempt any 
operations on behalf of the subshell, that I see.
On Monday, March 16, 2020 Joerg Schilling <joerg.schill...@fokus.fraunhofer.de> 
wrote:
Dirk Fieldhouse <fieldho...@gmx.net> wrote:

> On 15/03/20 16:43, Harald van Dijk wrote:
> >...>  >
> > "Before the shell terminates" is not limited to "before the top level
> > shell terminates". If a shell terminates, even if it is a subshell that
> > terminates, any EXIT trap action should be run.
>
> Sure, that is the intended interpretation, but this requirement in the
> DESCRIPTION of 'exit'
>
> "... If the current execution environment is a subshell environment, the
> shell shall exit from the subshell environment with the specified exit
> status and continue in the environment from which that subshell
> environment was invoked; otherwise, the shell utility shall terminate
> with the specified exit status. ..."
>

-------->
The environment in which the shell executes a trap on EXIT shall be identical 
to the environment immediately after the last command executed before the trap 
on EXIT was taken.
<-------

This implies that the exit trap is called from within exit(1), but return(1) 
does not call exit(1) nor is it an alias for exit(1).

Jörg

-- 
 EMail:jo...@schily.net                    (home) Jörg Schilling D-13353 Berlin
    joerg.schill...@fokus.fraunhofer.de (work) Blog: http://schily.blogspot.com/
 URL: http://cdrecord.org/private/ http://sf.net/projects/schilytools/files/'

Reply via email to