Subject: Re: sh exit trap problem
To: J Chapman Flack <flack@cs.purdue.edu>
From: Greywolf <greywolf@starwolf.com>
List: current-users
Date: 01/10/2005 14:48:55
[Thus spake J Chapman Flack ("JCF: ") 3:09pm...]
JCF: Wolfgang Rupprecht wrote:
JCF: > Under bash, when [the shell executing the following script exits on an
JCF: > untrapped SIGINT, the EXIT trap is taken]. Under sh, nothing happens other
JCF: > than the shell script terminating immediately. Is this a bug or
JCF: > simply undefined behavior that sh is implementing differently?
JCF: >
JCF: > #!/bin/sh
JCF: > # this sets the handler correctly in bash, but not in /bin/sh
JCF: > trap "echo caught pseudo-sig EXIT" 0
JCF: > sleep 3
JCF:
JCF: That's a good question - I just tried in a few shells in a few OSs and it
JCF: does seem to vary. bash takes the EXIT trap. real ksh does, pdksh doesn't.
JCF: Solaris and OpenServer sh do not. By the plain language in man pages and
JCF: POLA, it seems to me that the shells that don't take the trap are buggy, but
JCF: they're widespread and probably not going to be fixed. SUSv3 is amazingly
JCF: silent on the question. Can you accomplish what you want by directly
JCF: trapping SIGINT also?
I have found that if I want the trap 0 after an INT, I must tell the INT
handler to 'exit' as well.
JCF:
JCF: -Chap
JCF:
--*greywolf;
--
When will people learn how to think!?? I long for the day to come when
software is purchased on the basis of technical merit and usefulness and not
on the basis of marketing bullsh*t. And when is intelligence going to become
a prerequisite for survival?