Bug 590740 - 'set -e' works strange inside the subshell
Summary: 'set -e' works strange inside the subshell
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: bash (Show other bugs)
(Show other bugs)
Version: 6.0
Hardware: All Linux
low
medium
Target Milestone: rc
: ---
Assignee: Roman Rakus
QA Contact: BaseOS QE - Apps
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
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:
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: ---


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):

bash-4.1.2-2.el6.x86_64

How reproducible:

100%

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

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.