[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
set -e and subshells
From: |
Jon Salz |
Subject: |
set -e and subshells |
Date: |
Mon, 26 Sep 2005 12:46:29 -0400 |
I'm noticing a difference in behavior between Solaris 9's sh and GNU
bash, and was wondering if this is a bug or a feature.
Using GNU bash, version 3.00.16(1)-release (i386-redhat-linux-gnu).
This command:
bash -exc 'for x in a b c; do ( false ); echo status is $?; done'
loops through three items (a b c) and executes a failing command in a
subshell. I was expecting the outer shell to notice that the exit
status from the subshell is nonzero and terminate immediately; instead
it prints "status is 1" and continues looping.
+ for x in a b c
+ false
+ echo status is 1
status is 1
+ for x in a b c
+ false
+ echo status is 1
status is 1
+ for x in a b c
+ false
+ echo status is 1
status is 1
sh on Solaris does what I expected, namely just execute "false" once and
bail:
$ sh -exc 'for x in a b c; do ( false ); echo status is $?; done'
+ false
So... bug or feature? Thanks in advance for the help.
- Jon
- set -e and subshells,
Jon Salz <=