bug-bash
[Top][All Lists]
Advanced

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

"bash -e" does not stop if subshell returns an error


From: Andreas Luik
Subject: "bash -e" does not stop if subshell returns an error
Date: Fri, 19 Mar 2004 15:15:59 +0100

Configuration Information [Automatically generated, do not change]:
Machine: i386
OS: linux-gnu
Compiler: i386-redhat-linux-gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i386' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i386-redhat-linux-gnu' 
-DCONF_VENDOR='redhat' -DSHELL -DHAVE_CONFIG_H  -I.  -I. -I./include -I./lib 
-D_GNU_SOURCE  -O2 -g -pipe -march=i386 -mcpu=i686
uname output: Linux germain.s.orthogon.de 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 
2003 i686 i686 i386 GNU/Linux
Machine Type: i386-redhat-linux-gnu

Bash Version: 2.05b
Patch Level: 0
Release Status: release

Description:

"bash -e" is supposed to stop execution if a command returns an exit
status != 0.  This does not work for subshells.

Please compare:
pascal:~(216)> bash -ce 'for i in a b; do echo $i; false; done'
a
pascal:~(217)> bash -ce 'for i in a b; do (echo $i; false); done'
a
b

The first one is correct, the second one is not.  The following
command shows that the subshell indeed returns an exit status of 1,
therefore the loop should terminate:

pascal:~(218)> bash -ce 'for i in a b; do (echo $i; false); echo $?; done'
a
1
b
1

This behaviour is also an incompatibility with standard Bourne/SysV
Shells, e.g. the abovementioned command works on Sun Solaris with
/bin/sh:

solarishost:~(938)> sh -ce 'for i in a b; do (echo $i; false); done'
a

It also works with "zsh" on Linux:

pascal:~(219)> zsh -ce 'for i in a b; do (echo $i; false); done'
a

Repeat-By:
% bash -ce 'for i in a b; do (echo $i; false); done'

expected output:
a





reply via email to

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