bug-bash
[Top][All Lists]
Advanced

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

Doc of "set -e" should mention non-locality


From: Rainer Blome
Subject: Doc of "set -e" should mention non-locality
Date: Thu, 28 Jun 2012 14:37:17 +0200

Configuration Information [Automatically generated, do not change]:
Machine: i586
OS: linux-gnu
Compiler: gcc -I/usr/src/packages/BUILD/bash-3.2 
-L/usr/src/packages/BUILD/bash-3.2/../readline-5.2
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i586' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i586-suse-linux-gnu' 
-DCONF_VENDOR='suse' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -march=i586 -mtune=i686 
-fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector 
-funwind-tables -fasynchronous-unwind-tables -g -D_GNU_SOURCE -DRECYCLES_PIDS 
-Wall -g -std=gnu89 -Wextra -Wno-unprototyped-calls -Wno-switch-enum -pipe 
-fPIE -fprofile-use
uname output: Linux spatzenhorst 2.6.27.23-0.1-pae #1 SMP 2009-05-26 17:02:05 
-0400 i686 i686 i386 GNU/Linux
Machine Type: i586-suse-linux-gnu

Bash Version: 3.2
Patch Level: 39
Release Status: release

Description:

The implementation of "set -e" does not respect "lexical nesting".
This can be very surprising.  The documentation should explicitly
and clearly explain the behavior.

In a context of "set -e", with function "f() { x; false; y; }",
"f" will run only "x", while "f || true" will also run "y".
This is highly surprising.

The documentation states that "shell does not exit if the command that
fails is part of [a boolean expression]" (paraphrased). The problem
here is the phrase "is part of". At first glance, this appears to mean
"is lexically part of", because the wording refers to a number of
syntactical constructs.  This is the relevant sentence in full:

 The shell does not exit if the command that fails is part of the
 command list immediately following a while or until keyword, part of
 the test in an if statement, part of a && or || list, or if the
 command's return value is being inverted via !.

However, "is part of" apparently does not mean "is lexically part of".
Instead, it means "is executed in the execution context of", as in "is
executed when a preceding stack frame represents".

Repeat-By:

 set -e; f() { echo before; false; echo after; }; f || true; echo rc=$?;

prints:

----
before
after
rc=0
----

while many if not most programmers would expect it to print

----
before
rc=0
----


Fix:

If the effect is intended, clearly document it.
If not, change the implementation.

Note that some other shells, in particular ksh, implement the same
behavior.

-- 
NEU: FreePhone 3-fach-Flat mit kostenlosem Smartphone!                          
        
Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a



reply via email to

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