bug-bash
[Top][All Lists]
Advanced

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

Re: Issues with set -e and subshell


From: Chet Ramey
Subject: Re: Issues with set -e and subshell
Date: Fri, 30 Oct 2009 13:02:03 -0400
User-agent: Thunderbird 2.0.0.23 (Macintosh/20090812)

Mario TRENTINI wrote:

> Bash Version: 3.2
> Patch Level: 39
> Release Status: release
> 
> Description: Using set -e with subshell gives unexpected results
> 
> Repeat-By:
> 
> Hello,
> 
> First issue :
> 
> # The following works fine : end is displayed
> ( set -e ; echo Start ; false ; echo end )
> 
> # The following works in a different way : end is not displayed
> ( set -e ; echo Start ; false ; echo end ) || echo ERROR
> 
> # note that Bash 4 has the same behavior
> # (GNU bash, version 4.0.28(1)-release)
> 
> Is it a bug or the expected behavior, if it is a bug, is there a workaround ?

It is expected behavior.  The presence of || cancels set -e for the
command preceding the ||.

There are always workarounds.  You don't have to rely on set -e; you can
structure your code so that you manually check the exit status.

> Second issue :
> 
> # I expect the following to not display status but to exit the shell :
> set -e ; ( exit 1 ) ; echo status $?
> 
> # I observed the expected behavior on Bash 4.
> 
> Is there a way for Bash 3 to have the same behavior as Bash 4 ?

Not using `set -e'.  That's the essential substance of the bash-3.x-
bash-4.x change: the commands whose failure cause the shell to exit
were expanded from simple commands to nearly every command, including
pipelines and compound commands.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/




reply via email to

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