Bugzilla (bugzilla.redhat.com) will be under maintenance for infrastructure upgrades and will not be available on July 31st between 12:30 AM - 05:30 AM UTC. We appreciate your understanding and patience. You can follow status.redhat.com for details.
Bug 590740 - 'set -e' works strange inside the subshell
Summary: 'set -e' works strange inside the subshell
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: bash
Version: 6.0
Hardware: All
OS: Linux
Target Milestone: rc
: ---
Assignee: Roman Rakus
QA Contact: BaseOS QE - Apps
Depends On:
TreeView+ depends on / blocked
Reported: 2010-05-10 15:21 UTC by Kirby Zhou
Modified: 2014-01-13 00:11 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2010-05-11 18:28:36 UTC
Target Upstream Version:

Attachments (Terms of Use)

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

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