[Top][All Lists]

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

Re: set -e and subshells

From: Chet Ramey
Subject: Re: set -e and subshells
Date: Tue, 27 Sep 2005 08:56:57 -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.

It's a POSIX requirement.

> 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.

According to POSIX, `set -e' only affects the execution of simple commands.
A command in a subshell is not a simple command.

You can look at the grammar at


``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )
                                                Live Strong.
Chet Ramey, ITS, CWRU    address@hidden    http://tiswww.tis.case.edu/~chet/

reply via email to

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