autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 'set -e' and 'if eval false' exits with BSD sh


From: Ralf Wildenhues
Subject: Re: 'set -e' and 'if eval false' exits with BSD sh
Date: Sat, 28 Oct 2006 14:38:42 +0200
User-agent: Mutt/1.5.13 (2006-08-11)

Hello Paul,

* Paul Eggert wrote on Sat, Oct 28, 2006 at 08:56:01AM CEST:
> Ralf Wildenhues <address@hidden> writes:
> 
> > On FreeBSD 6.1 and OpenBSD 3.9, 'set -e' will cause failing eval
> > commands to exit even in an AND (&&) list or as the compound list 
> > after 'if':
> 
> I would argue that the standard is ambiguous, and that these
> implementations therefore conform.
[...]

Thank you for the explanations.  I see that there are similar semantic
differences, e.g., with constructs such as
  set -e
  { false; :; } || :
  echo bash prints this, BSD sh does not.

So let's back down a bit.  My patch also contained some simplification
and version update of another example, see below; OK to apply?

FWIW, I'd wish POSIX were clearer in this respect.  Something like
  Whether the shell exits if some part of a non-simple command failed
  is implementation-defined.

would help to be more aware of this, and some clarification of whether
  eval false

is considered a simple command, compound command, or something else.

Cheers,
Ralf

2006-10-27  Ralf Wildenhues  <address@hidden>

        * doc/autoconf.texi (Limitations of Builtins): Use 'false'
        for simplicity in 'set -e' example.  Suggested by Akim Demaille.
        Update version information.

Index: doc/autoconf.texi
===================================================================
RCS file: /cvsroot/autoconf/autoconf/doc/autoconf.texi,v
retrieving revision 1.1104
diff -u -r1.1104 autoconf.texi
--- doc/autoconf.texi   27 Oct 2006 23:01:06 -0000      1.1104
+++ doc/autoconf.texi   28 Oct 2006 12:28:00 -0000
@@ -12662,25 +12662,24 @@
 wrapper works around the bug.
 
 Even relatively-recent versions of the @acronym{BSD} shell (e.g.,
address@hidden 3.4) wrongly exit with @option{-e} if a command within
address@hidden 3.9) wrongly exit with @option{-e} if a command within
 @samp{&&} fails inside a compound statement.  For example:
 
 @example
 #! /bin/sh
 set -e
-foo=''
-test -n "$foo" && exit 1
+false && exit 1
 echo one
 if :; then
-  test -n "$foo" && exit 1
+  false && exit 1
 fi
 echo two
 @end example
 
 @noindent
-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}.
+does not print @samp{two}.  One workaround is to use @samp{if false; then
+exit 1; fi} rather than @samp{false && exit 1}.  Another possibility is to
+warn @acronym{BSD} users not to use @samp{sh -e}.
 
 
 @item @command{shift}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]