Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15670 > unrolled thread
| Started by | Chet Ramey <chet.ramey@case.edu> |
|---|---|
| First post | 2019-11-13 10:07 -0500 |
| Last post | 2019-11-13 10:07 -0500 |
| Articles | 1 — 1 participant |
Back to article view | Back to gnu.bash.bug
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: set -e ignored in subshell if part of command list Chet Ramey <chet.ramey@case.edu> - 2019-11-13 10:07 -0500
| From | Chet Ramey <chet.ramey@case.edu> |
|---|---|
| Date | 2019-11-13 10:07 -0500 |
| Subject | Re: set -e ignored in subshell if part of command list |
| Message-ID | <mailman.1343.1573657685.13325.bug-bash@gnu.org> |
On 11/13/19 5:24 AM, Shaun Crampton wrote: > Bash Version: 5.0 > Patch Level: 3 > Release Status: release > > Description: > I was trying to get a function to return early if a command > fails by putting > the body of the function in a subshell and using set -e inside > the subshell. > If I run a subshell on its own, this works, but when I try to combine it > into a larger program, the set -e gets ignored. > > Repeat-By: > Managed to boil it down to this smaller example: > > # On its own, subshell behaves as expected: > $ ( set -ex; false; echo here ) > + false > > # In a list, behaviour changes, "echo here" gets executed: > $ ( set -ex; false; echo here ) && echo there > + false > + echo here > here > there The subshell command is part of an and-or list, so the -e is ignored for that command: "The -e setting shall be ignored when executing the compound list following the while, until, if, or elif reserved word, a pipeline beginning with the ! reserved word, or any command of an AND-OR list other than the last." (from https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_25_03) The subshell inherits this state (being part of an and-or list) from its parent. > > # If the subshell is executed in the background, it works > $ ( set -e; false; echo here ) & pid=$!; wait $pid && echo there In this command, the subshell is not part of an and-or list. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
Back to top | Article view | gnu.bash.bug
csiph-web