Hello,

On Mon, Oct 31, 2005 at 11:53:23PM -0800, Kean Johnston wrote:
> >I looked at POSIX, and 'trap - 0' is standardized, while 'trap 0' is not.

> Ok thats a fair comment. But then if you want to use POSIX
> shell scripts shouldn't you ensure you are running in a
> POSIX shell?

I agree that the priority is to use a portable solution.
But among them, the standards conforming should be preferred--it's kind of
"future portability".  Moreover, people will read the scripts: we shouldn't
teach them portable non-conforming hacks, if there are portable conforming
ones available.  ;-)

> > [...] would "trap '' 0" work?  Or perhaps "trap : 0"?

> Both do, but trap '' 0 seems to be the most portable.

And it is also the clener one.
Proposed patch attached.

I'm also attaching a proposed patch for the Autoconf manual.
Could someone please verify whether "trap - SIG" is supported on recent
versions of Solaris and HPUX?

Have a nice day,
        Stepan Kasal
2005-11-01  Stepan Kasal  <[EMAIL PROTECTED]>

        * lib/install-sh: Use "trap '' 0" instead of "trap - 0".

Index: lib/install-sh
===================================================================
RCS file: /cvsroot/automake/automake/lib/install-sh,v
retrieving revision 1.26
diff -u -r1.26 install-sh
--- lib/install-sh      13 Sep 2005 23:14:56 -0000      1.26
+++ lib/install-sh      1 Nov 2005 08:23:07 -0000
@@ -389,7 +389,7 @@
         }
     } || exit 1
 
-    trap - 0
+    trap '' 0
   fi
 done
 
2005-11-01  Stepan Kasal  <[EMAIL PROTECTED]>

        * doc/autoconf.texi (Limitations of Builtins): Document that
        "trap - SIG" is not yet portable.

Index: doc/autoconf.texi
===================================================================
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.932
diff -u -r1.932 autoconf.texi
--- doc/autoconf.texi   21 Oct 2005 05:46:50 -0000      1.932
+++ doc/autoconf.texi   1 Nov 2005 08:46:24 -0000
@@ -11365,7 +11365,7 @@
 RISC/OS} 4.52 refuses to do it.
 
 Don't use @samp{shift 2} etc.; it was not in the 7th Edition Bourne shell,
-and it is also absent in many pre-POSIX shells.
+and it is also absent in many pre-Posix shells.
 
 
 @item @command{source}
@@ -11488,6 +11488,27 @@
 It is safe to trap at least the signals 1, 2, 13, and 15.  You can also
 trap 0, i.e., have the @command{trap} run when the script ends (either via an
 explicit @command{exit}, or the end of the script).
+
+But even though Posix defines that the trap can be unset by
[EMAIL PROTECTED] - SIG}, the feature is not widely supported yet.
+But it si safe to use @samp{trap '' SIG} to ignore the signal; in particular,
[EMAIL PROTECTED] '' 0} is a portable way to clear the trap 0.
+
[EMAIL PROTECTED]
+The above is based on report:
+
+From: Kean Johnston <[EMAIL PROTECTED]>
+Date: Mon, 31 Oct 2005 23:53:23 -0800
+Cc: [email protected], [email protected], [email protected]
+Message-ID: <[EMAIL PROTECTED]>
+
+[trap - 0 doesn't work on] SCO OpenServer 5, SCO OpenServer 6, SCO UnixWare 2,
+SCO UnixWare 7. But I took a look around ...
+http://docs.sun.com/app/docs/doc/816-5165/6mbb0m9sa?a=view#indexterm-694
+(Solaris 10 man page for sh) doesn't support trap - either, but
+it does support the null string as an argument. Same with HPUX 11
+(http://docs.hp.com/en/B2355-90680/sh-bourne.1.html).
[EMAIL PROTECTED] ignore
 
 Although Posix is not absolutely clear on this point, it is widely
 admitted that when entering the trap @samp{$?} should be set to the exit

Reply via email to