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    c...@case.edu    http://cnswww.cns.cwru.edu/~chet/


Reply via email to