From: Ben Bacarisse on 8 Jun 2010 18:37 Martin Vaeth <vaeth(a)mathematik.uni-wuerzburg.de> writes: > Ben Bacarisse <ben.usenet(a)bsb.me.uk> wrote: >> >> trap - SIGINT >> >> [...] Note that I prefer SIGxxx signal names > > This is not a good idea since it is not POSIX. > For example, dash will not understand it. Useful to know. Thanks. -- Ben.
From: Geoff Clare on 9 Jun 2010 08:35 Ben Bacarisse wrote: > To return to whatever the default is use: > > trap SIGINT > > or > > trap - SIGINT The second of those will work (if, as Martin Vaeth pointed out, the shell accepts the SIG prefix, which POSIX doesn't require). However, the first will give an error message in bash and ksh (even though they support the SIG prefix), as the operand "SIGINT" is taken as an action to perform, and no conditions have been specified for that action. The first form only works with numeric signals, e.g. "trap 2". -- Geoff Clare <netnews(a)gclare.org.uk>
From: Thomas 'PointedEars' Lahn on 9 Jun 2010 09:17 Martin Vaeth wrote: > Ben Bacarisse <ben.usenet(a)bsb.me.uk> wrote: >> trap - SIGINT >> >> [...] Note that I prefer SIGxxx signal names > > This is not a good idea since it is not POSIX. I am afraid you are mistaken: ,-<http://www.opengroup.org/onlinepubs/000095399/utilities/trap.html> | | NAME | | trap - trap signals | | SYNOPSIS | | trap [action condition ...] | | DESCRIPTION | | [...] | The condition can be EXIT, 0 (equivalent to EXIT), or a signal specified | using a symbolic name, without the SIG prefix, as listed in the tables | of signal names in the <signal.h> header defined in the Base | Definitions volume of IEEE Std 1003.1-2001, Chapter 13, Headers; for | example, HUP, INT, QUIT, TERM. Implementations may permit names with the | SIG prefix or ignore case in signal names as an extension. Setting a | trap for SIGKILL or SIGSTOP produces undefined results. > For example, dash will not understand it. Because the Specification does allow, but does not require conforming implementations to support the "SIG" prefix. Thanks for the hint, though. PointedEars
From: Ben Bacarisse on 9 Jun 2010 09:27 Geoff Clare <geoff(a)clare.See-My-Signature.invalid> writes: > Ben Bacarisse wrote: > >> To return to whatever the default is use: >> >> trap SIGINT >> >> or >> >> trap - SIGINT > > The second of those will work (if, as Martin Vaeth pointed out, the > shell accepts the SIG prefix, which POSIX doesn't require). However, > the first will give an error message in bash and ksh (even though > they support the SIG prefix), as the operand "SIGINT" is taken as an > action to perform, and no conditions have been specified for that > action. The first form only works with numeric signals, e.g. "trap > 2". That seems to be true for ksh but not for bash, at least not for recent bash versions. Both forms work in my installed bash (and zsh for that matter) and both are documented to work. Of course, this is not an argument for using that form -- just a remark that shell syntax more diverse than one would like. It is clear that "trap - INT" is the form to choose. -- Ben.
From: Chad on 9 Jun 2010 13:05
On Jun 9, 6:27 am, Ben Bacarisse <ben.use...(a)bsb.me.uk> wrote: > Geoff Clare <ge...(a)clare.See-My-Signature.invalid> writes: > > Ben Bacarisse wrote: > > >> To return to whatever the default is use: > > >> trap SIGINT > > >> or > > >> trap - SIGINT > > > The second of those will work (if, as Martin Vaeth pointed out, the > > shell accepts the SIG prefix, which POSIX doesn't require). However, > > the first will give an error message in bash and ksh (even though > > they support the SIG prefix), as the operand "SIGINT" is taken as an > > action to perform, and no conditions have been specified for that > > action. The first form only works with numeric signals, e.g. "trap > > 2". > > That seems to be true for ksh but not for bash, at least not for recent > bash versions. Both forms work in my installed bash (and zsh for that > matter) and both are documented to work. Of course, this is not an > argument for using that form -- just a remark that shell syntax more > diverse than one would like. > > It is clear that "trap - INT" is the form to choose. > I think I just missed something here. Why would you use "trap - INT" and not something like "trap - SIGINT"? Chad |