From: Eric Blake Date: Tue, 18 Nov 2008 15:45:04 +0000 (-0700) Subject: Document Tru64 bug with 'set -e'. X-Git-Tag: v2.63b~97 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fed7af3616b516067643c4a4abbb203ea5622841;p=thirdparty%2Fautoconf.git Document Tru64 bug with 'set -e'. * doc/autoconf.texi (Limitations of Builtins) : Mention a bug in mixing 'set -e' with 'trap .. 0'. Reported by Ralf Wildenhues. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index 93c085c77..543ce5d96 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,10 @@ 2008-11-18 Eric Blake + Document Tru64 bug with 'set -e'. + * doc/autoconf.texi (Limitations of Builtins) : Mention a + bug in mixing 'set -e' with 'trap .. 0'. + Reported by Ralf Wildenhues. + Document a Solaris /bin/sh bug with 'set -e'. * doc/autoconf.texi (Shell Functions): Mention the bug. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index 90e6ceee2..37becc5f1 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -15425,6 +15425,22 @@ does not print @samp{two}. One workaround is to use @samp{if test -n "$foo"; then exit 1; fi} rather than @samp{test -n "$foo" && exit 1}. Another possibility is to warn @acronym{BSD} users not to use @samp{sh -e}. +Portable scripts should not use @samp{set -e} if @command{trap} is used +to install an exit handler. This is because Tru64/OSF 5.1 @command{sh} +enters the trap handler with the exit status of the command prior to the +one that triggered the errexit handler: + +@example +$ @kbd{bash -c 'trap '\''echo $?'\'' 0; set -e; false'} +1 +$ @kbd{sh -c 'trap '\''echo $?'\'' 0; set -e; false'} +0 +@end example + +@noindent +Thus, when writing a script in M4sh, rather than trying to rely on +@samp{set -e}, it is better to append @samp{|| AS_EXIT([$?])} to any +statement where it is desirable to abort on failure. @item @command{shift} @c ------------------