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

Re: trap does not work in a trap function?



On 9 September 2010 10:57, Peter Stephenson <Peter.Stephenson@xxxxxxx> wrote:
> On Thu, 09 Sep 2010 10:17:33 +0200
> "Dominik Vogt" <dominik.vogt@xxxxxx> wrote:
>> shutdown () {
>>       echo shutdown
>>       trap - EXIT
>>       exit 77
>> }
>>
>> trap shutdown EXIT
>> shutdown
>> -- END sigtest
>>
>> >   $ ./sigtest
>> >   shutdown
>> >   shutdown
>> >
>> > Why is the shutdown function called again by exit when the EXIT
>> > trap was just removed?  This looks like the trap builtin does not
>> > properly work from within a trap handler.
>
> The EXIT trap you removed was the one for the "shutdown" function.  In zsh,
> EXIT is used with functions as well as scripts.
>
> You can do what you want like this:
>
> shutdown () {
>  echo shutdown
>  trap 'trap - EXIT' EXIT
>  exit 77
> }
>
> unless shutdown is itself called from within a function, in which case
> you're removing the EXIT trap for that.

Could you also use "SIGEXIT() shutdown" and "unfunction SIGEXIT"
instead, regardless of the amount of function nesting? (It seems to
work when I try it).

-- 
Mikael Magnusson



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