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 Newsgroups: gnu.bash.bug Subject: Re: set -e ignored in subshell if part of command list Date: Wed, 13 Nov 2019 11:43:53 -0500 Lines: 60 Approved: bug-bash@gnu.org Message-ID: References: <5dcc2873.17477@msgid.achurch.org> 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 1573663448 2600 209.51.188.17 (13 Nov 2019 16:44:08 GMT) X-Complaints-To: action@cs.stanford.edu Cc: chet.ramey@case.edu, bug-bash@gnu.org To: Andrew Church Envelope-to: bug-bash@gnu.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1573663436; bh=d13Vi5j/9bZPwnucSqvqVJI3TPRDaMhFokmYn6raeI4=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=PaoPpZfvGYmM8wcFsZWwcSnrGYCp7doZD6hIa/oqE2FEqP0ZttxU/3R+1tfuR2hRt5 1S2YQ0yqv4XAVocBadhurdMyrOgXHLLFvkVFYxL4oaYWlsEWY9cV1BAAuTyOWXX0cpx eVHCWBzAWany89VMa1+wtGIkd9HlxbI4hQ0LPJ/JSIohwgb/q87nrvBSKBXNXHIrbTT BazvmPhPDuMKZ12wedgI6NVJfi+VK+KpJhFQH3qEtiTeFC0bCsl/G1p8PVS80AnEu4N lbP1ZJ23nIjHjPQAnvtn/li+3M8zB6uCmRy9/+/Eqwg7HL9I4qxqM6/fAb3HRCgVzTM qbkDKrFw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=case.edu; s=smtp-primary; t=1573663434; bh=l3LclAx3uI4PJyoBEaO7gsKg78Py8MMnLrvuPPXrCJY=; h=Reply-To:Cc:Subject:To:References:From:Message-ID:Date: MIME-Version:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=KVvXBzA4vfqXDIJcelTCLeskOjDKu8IOYFb0M5neszVSRjcS4i9tfpJbIPj03vJgWM xbk8HdEaoGY0VJKdVADEdVZtbh892SKDuC6oDtZxbyC+3HZOacL5TKqb3LkjGAUjZ5u +P7zxtDyZR9ZtZn1mY9Q73SkV8uWoF3rli2cnse1r6KVRTEEElt5ATIiEtd+ZBcv1Wc wDJ14yGG50CcgXsIz08efBAaZHmxZ2Iahg81o+frSXHOnwQfkcnH8BhDXcYpviRPSPt An3bqR5xvfxgcH1yIaqzVbbw5WPbI0y9SRZL3hUTi0lstBJ25URjGocjEAvsvx4yrUL A4fWzf/A== User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 In-Reply-To: <5dcc2873.17477@msgid.achurch.org> Content-Language: en-US X-Junkmail-Status: score=8/90, host=mpv2-2015.case.edu X-Junkmail-PrAS-Raw: score=8/90, refid=2.7.2:2019.11.13.155417:17:8.317, ip=, rules=DKIM_SIGNATURE, __HAS_REPLYTO, __HAS_CC_HDR, __MULTIPLE_RCPTS_CC_X2, __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_CC2, __REPLYTO_SAMEAS_FROM_DOMAIN, __DKIM_ALIGNS_1, __DKIM_ALIGNS_2, URI_ENDS_IN_PHP, __ANY_URI, __URI_MAILTO, __HTTPS_URI, __URI_WITH_PATH, __URI_NO_WWW, __CP_URI_IN_BODY, __SUBJ_ALPHA_NEGATE, __MULTIPLE_URI_TEXT, __URI_IN_BODY, __URI_NOT_IMG, __FORWARDED_MSG, __BODY_NO_MAILTO, __NO_HTML_TAG_RAW, BODYTEXTP_SIZE_3000_LESS, BODY_SIZE_2000_2999, __MIME_TEXT_P1, __MIME_TEXT_ONLY, [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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <5dcc2873.17477@msgid.achurch.org> Xref: csiph.com gnu.bash.bug:15675 On 11/13/19 10:59 AM, Andrew Church wrote: >> "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. > > Is that really the intent of the requirement, though? Yes. > The same section > states: "This requirement applies to the shell environment and each > subshell environment separately", which I read to mean that the rules > should be evaluated without consideration of any parent or subshell > environment other than the one in which the -e option is being applied. Not quite. It means that the reasons a subshell (for instance) exits may not be the same ones applied to the parent. > And the example: > > set -e; (false; echo one) | cat; echo two > > shows rule 1 ("The failure of any individual command in a multi-command > pipeline shall not cause the shell to exit") OK. The "individual command" in this context is the subshell command. The subshell command exits with a non-zero status, but that doesn't cause the shell to exit. The -e setting isn't ignored in the subshell because it's not in an and-or list. > not being applied within > the subshell, even though the subshell as a whole is an "individual > command in a multi-command pipeline". I don't see any suggestion that > the case of an AND-OR list in rule 2 should be treated differently, and > absent an explicit requirement one way or the other, I think the > expected behavior here would be that the behavior of the subshell is > independent of the subshell's context in the parent shell. The "-e setting shall be ignored" part? Expectations aside, that's just not how shells behave, and not the intent of the standard. This was discussed pretty thoroughly back in 2009, and shell behavior reflects the consensus from that discussion. As I said in another message, there was a proposal for some stronger language ("-e is disabled and cannot be re-enabled when executing...any command of an AND-OR list except the last" is another version of the proposed language) but that was deemed unnecessary. The relevant interpretation was http://austingroupbugs.net/view.php?id=52 but there's not much discussion there -- it was all on the mailing 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/