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 11:56, Peter Stephenson <Peter.Stephenson@xxxxxxx> wrote:
> On Thu, 9 Sep 2010 11:44:49 +0200
> Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
>> 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).
>
> What's supposed to happen is the trap, however it is set, is saved and
> unset during the function, then restored afterwards (before the scope in
> which the function's EXIT trap is run, hence the workaround).  So this
> isn't supposed to work.  I get the following:
>
> % TRAPEXIT() { echo This is the exit trap; }
> % fn() { unfunction TRAPEXIT; }
> % fn
> fn:unfunction: no such hash table element: TRAPEXIT
> % functions TRAPEXIT
> TRAPEXIT () {
>        echo This is the exit trap
> }
> % exit
> This is the exit trap

Ah, I had SIG instead of TRAP which obviously didn't work, which had
the side effect of looking like it worked ;).

-- 
Mikael Magnusson



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