Bug 590740

Summary: 'set -e' works strange inside the subshell
Product: Red Hat Enterprise Linux 6 Reporter: Kirby Zhou <kirbyzhou>
Component: bashAssignee: Roman Rakus <rrakus>
Status: CLOSED NOTABUG QA Contact: BaseOS QE - Apps <qe-baseos-apps>
Severity: medium Docs Contact:
Priority: low    
Version: 6.0CC: tsmetana
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2010-05-11 18:28:36 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Description Kirby Zhou 2010-05-10 15:21:10 UTC
Description of problem:

'set -e' works strange inside the subshell.

I think (set -e; ... ) should keep behavior invariantly with different contexts, but it does not. Sometimes 'set -e' is ignored with '&&'/'||' around the bracket.

In my opinion, all cases below should not execute 'echo norun', but some cases did run it.

Version-Release number of selected component (if applicable):


How reproducible:


Steps to Reproduce:

]# (set -e -x ; false ; echo norun ) || true
+ false
+ echo norun

]# (set -e -x ; false ; echo norun ) && true
+ false
+ echo norun

]# ! (set -e -x ; false ; echo norun )
+ false

]# false || (set -e -x ; false ; echo norun )   
+ false

]# true && (set -e -x ; false ; echo norun )  
+ false

]# (set -e -x ; false ; echo norun ) 
+ false

Comment 2 RHEL Product and Program Management 2010-05-10 16:54:28 UTC
This request was evaluated by Red Hat Product Management for inclusion in a Red
Hat Enterprise Linux major release.  Product Management has requested further
review of this request by Red Hat Engineering, for potential inclusion in a Red
Hat Enterprise Linux Major release.  This request is not yet committed for

Comment 3 Roman Rakus 2010-05-11 18:28:36 UTC
This is nicely documented. See man page of set builtin;
-e      Exit immediately if a pipeline (which may consist  of  a
                      single  simple command),  a subshell command enclosed in
                      parentheses, or one of the commands executed as part  of
                      a  command  list  enclosed  by braces (see SHELL GRAMMAR
                      above) exits with a non-zero status.  The shell does not
                      exit  if  the  command that fails is part of the command
                      list immediately following a  while  or  until  keyword,
                      part  of  the  test  following  the  if or elif reserved
                      words, part of any command executed in a && or  ││  list
                      except  the  command  following  the final && or ││, any
                      command in a pipeline but the last, or if the  command’s
                      return  value  is being inverted with !.  A trap on ERR,
                      if set, is executed before the shell exits.  This option
                      applies to the shell environment and each subshell envi-
                      ronment separately (see  COMMAND  EXECUTION  ENVIRONMENT
                      above), and may cause subshells to exit before executing
                      all the commands in the subshell.