Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: 4.3.11 TRAPEXIT() on cygwin



On 11 January 2011 03:54, Anthony Heading <anthony@xxxxxxxx> wrote:
> On Tue, 11 Jan 2011 02:50 +0100, "Mikael Magnusson" <mikachu@xxxxxxxxx>
> wrote:
>> > echo $( trap 'echo exiting' EXIT)
>> >
>> > or similar substitutions.  That's quite clearly a subshell entering to
>> > the same extent a ( ... ) is.
>>
>> How is that different from what you wrote?
>
> Well, the examples you quote are traps set within a subshell, which may
> or may not propagate higher.
>
> My problem is that the subshell is inheriting the parent trap action.
>
> That seems obviously different, and POSIX seems pretty clear:
>
>    When a subshell is entered, traps that are not being ignored shall
>    be set to the default actions, except in the case of a command
>    substitution containing only a single trap command, when the traps
>    need not be altered.

Ah, the manpage says this
       ( list )
              Execute  list  in a subshell.  Traps set by the trap
builtin are reset
              to their default values while executing list.

and it is true:
% trap 'echo hello >&2' EXIT
% a=$(ls)
% TRAPEXIT() { echo function hello >&2 }
% a=$(ls)
function hello

-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author