Bugzilla will be upgraded to version 5.0 on a still to be determined date in the near future. The original upgrade date has been delayed.
Bug 590740 - 'set -e' works strange inside the subshell
'set -e' works strange inside the subshell
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: bash (Show other bugs)
All Linux
low Severity medium
: rc
: ---
Assigned To: Roman Rakus
BaseOS QE - Apps
Depends On:
  Show dependency treegraph
Reported: 2010-05-10 11:21 EDT by Kirby Zhou
Modified: 2014-01-12 19:11 EST (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2010-05-11 14:28:36 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Kirby Zhou 2010-05-10 11:21:10 EDT
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 12:54:28 EDT
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 14:28:36 EDT
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.

Note You need to log in before you can comment on or make changes to this bug.