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

Re: How to trap EXIT like in bash



On Apr 4,  9:41pm, Thorsten Kampe wrote:
}
} >     zshexit() { echo trapped }
} >     trap exit HUP INT TERM
} 
} As stated to Philippe: this works in regard to exit and INT, but not 
} for HUP and TERM. The script ignores any `kill PID` request.
} 
} Tested on Cygwin and Ubuntu 14.10.

Oh.  You need "setopt TRAPS_ASYNC":

     While waiting for a program to exit, handle signals and run traps
     immediately.  Otherwise the trap is run after a child process has
     exited.  Note this does not affect the point at which traps are
     run for any case other than when the shell is waiting for a child
     process.

The signal isn't ignored, it just isn't handled right away.  Normally any
foreground child process is the "group leader" and receives the signals
before the parent shell.

I wonder if this should be on by default in "sh" emulation.



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