Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #15670
| Path | csiph.com!tncsrv06.tnetconsulting.net!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Chet Ramey <chet.ramey@case.edu> |
| Newsgroups | gnu.bash.bug |
| Subject | Re: set -e ignored in subshell if part of command list |
| Date | Wed, 13 Nov 2019 10:07:44 -0500 |
| Lines | 52 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.1343.1573657685.13325.bug-bash@gnu.org> (permalink) |
| References | <CAMhR0U1fzAvXMVZacEYf9yAPwgq_6Gz5C-99dj6xt=9pQMtX8Q@mail.gmail.com> <13040a55-507d-e072-e827-be7c33be968f@case.edu> |
| Reply-To | chet.ramey@case.edu |
| NNTP-Posting-Host | lists.gnu.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | usenet.stanford.edu 1573657686 32164 209.51.188.17 (13 Nov 2019 15:08:06 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| Cc | chet.ramey@case.edu |
| To | Shaun Crampton <shaun@tigera.io>, bug-bash@gnu.org |
| Envelope-to | bug-bash@gnu.org |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1573657679; bh=aI3hBvfMDATCvRpD9jC6mwFrnkOWK7FVTo+hDYKoppk=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=kNit/XmaHkOHQ+pGQtrMVz0Y4kuGO/i5xCIacbD1J3yZaau5lTRKbv34VCzdA9tv6N 79Gnzpwta5e3aHCeoSpMqwV5BB5ZmIO8kJDD0n4lnse7hkd6KoWDhyT5/Y65aFcgu2U EV0pGPyVaYa4Q7U8P9Zl4lSpfA3Ns1XGzc/ZGnDSmmugkChPD9+XaZkBrzheJhwpTvl iyrY8vWykSL4YNrq7IDU4N3nN4kq4hbcflr+NGuVsqdTBCIGGK7gpkpR8rg18CwSEe5 LuYdMXaZB6jbi+irPxRcfTao0E0ru8LGBBrpLSLjxuIxzYDyexPQzCdrO6eV52V5SK0 Z5E8wb7A== |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1573657673; bh=iTTjE6am1oLIyw51szNX806gYrzMXyYeM7LlqnuNxyc=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=d2cymF6jyrQccHDIK2gXsYjVD7Ne0bq+itXFqW/VU9VB+f9CuD/t36/3xMw9d/1KP+ bA1U43Jn8VC4WN7TxsMr4KaPAhYk96BaHcHHYpOQxUuu0naj6fCwHJyZn/MYNX7nV3K /9TumZcZYA9GYd27nFDV09ywn+T8hypG/OjQbA3sYKqMaS6gH08LUm+Lc7jPPQ8J7bI B5H7elvs8gHw6dOn0CVCMYD5YuXW0A62AsDoShzZflnsh4X8zCKorMB+toxAuDnnY1V cbPrePLrZ+1zF5yoibleqNUai6/CACqaEbVqAp6V0VTAss5fA9JG7CQcDO5LTGfVVEj n+Qmkysw== |
| User-Agent | Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 |
| In-Reply-To | <CAMhR0U1fzAvXMVZacEYf9yAPwgq_6Gz5C-99dj6xt=9pQMtX8Q@mail.gmail.com> |
| Content-Language | en-US |
| X-Junkmail-Status | score=7/90, host=mpv2-2015.case.edu |
| X-Junkmail-PrAS-Raw | score=7/90, refid=2.7.2:2019.11.13.135416:17:7.944, ip=, rules=DKIM_SIGNATURE, __HAS_REPLYTO, __HAS_CC_HDR, __SUBJ_REPLY, __BOUNCE_CHALLENGE_SUBJ, __BOUNCE_NDR_SUBJ_EXEMPT, __SUBJ_ALPHA_END, __TO_MALFORMED_2, __TO_NAME, __TO_NAME_DIFF_FROM_ACC, __HAS_REFERENCES, __REFERENCES, __HAS_FROM, FROM_EDU_TLD, __HAS_MSGID, __SANE_MSGID, DATE_TZ_NA, __USER_AGENT, __MOZILLA_USER_AGENT, __MIME_VERSION, __IN_REP_TO, __CT, __CT_TEXT_PLAIN, __CTE, __REPLYTO_SAMEAS_FROM_ADDY, __REPLYTO_SAMEAS_FROM_ACC, __FROM_DOMAIN_IN_ANY_CC1, __FROM_DOMAIN_IN_ANY_CC2, __REPLYTO_SAMEAS_FROM_DOMAIN, __DKIM_ALIGNS_1, __DKIM_ALIGNS_2, __ANY_URI, __URI_MAILTO, __HTTPS_URI, __URI_WITH_PATH, __URI_NO_WWW, __CP_URI_IN_BODY, __FRAUD_MONEY_CURRENCY_DOLLAR, __SUBJ_ALPHA_NEGATE, __MULTIPLE_URI_TEXT, __URI_IN_BODY, __URI_NOT_IMG, __FORWARDED_MSG, __BODY_NO_MAILTO, __NO_HTML_TAG_RAW, BODY_SIZE_1700_1799, BODYTEXTP_SIZE_3000_LESS, __MIME_TEXT_P1, [TRUNCATED], so=2010-03-03 19:42:08, dmn=2016-08-03-0138 |
| X-detected-operating-system | by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] [fuzzy] |
| X-Received-From | 129.22.103.227 |
| X-BeenThere | bug-bash@gnu.org |
| X-Mailman-Version | 2.1.23 |
| Precedence | list |
| List-Id | Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org> |
| List-Unsubscribe | <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe> |
| List-Archive | <https://lists.gnu.org/archive/html/bug-bash> |
| List-Post | <mailto:bug-bash@gnu.org> |
| List-Help | <mailto:bug-bash-request@gnu.org?subject=help> |
| List-Subscribe | <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <13040a55-507d-e072-e827-be7c33be968f@case.edu> |
| X-Mailman-Original-References | <CAMhR0U1fzAvXMVZacEYf9yAPwgq_6Gz5C-99dj6xt=9pQMtX8Q@mail.gmail.com> |
| Xref | csiph.com gnu.bash.bug:15670 |
Show key headers only | View raw
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 gnu.bash.bug | Previous | Next | Find similar | Unroll thread
Re: set -e ignored in subshell if part of command list Chet Ramey <chet.ramey@case.edu> - 2019-11-13 10:07 -0500
csiph-web