Subject: Re: sh exit trap problem
To: Wolfgang S. Rupprecht <>
From: J Chapman Flack <>
List: current-users
Date: 01/10/2005 15:09:54
Wolfgang Rupprecht wrote:
> Under bash, when [the shell executing the following script exits on an
> untrapped SIGINT, the EXIT trap is taken].  Under sh, nothing happens other
> than the shell script terminating immediately.  Is this a bug or
> simply undefined behavior that sh is implementing differently?
>     #!/bin/sh
>     # this sets the handler correctly in bash, but not in /bin/sh
>     trap "echo caught pseudo-sig EXIT" 0
>     sleep 3

That's a good question - I just tried in a few shells in a few OSs and it
does seem to vary.  bash takes the EXIT trap.  real ksh does, pdksh doesn't.
Solaris and OpenServer sh do not.  By the plain language in man pages and
POLA, it seems to me that the shells that don't take the trap are buggy, but
they're widespread and probably not going to be fixed.  SUSv3 is amazingly
silent on the question.  Can you accomplish what you want by directly
trapping SIGINT also?