From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: from primenet.com.au (ns1.primenet.com.au [203.24.36.2]) by inbox.vuxu.org (OpenSMTPD) with ESMTP id 6b7a0154 for ; Sat, 1 Feb 2020 19:29:14 +0000 (UTC) Received: (qmail 15274 invoked by alias); 1 Feb 2020 19:29:08 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45373 Received: (qmail 13883 invoked by uid 1010); 1 Feb 2020 19:29:08 -0000 X-Qmail-Scanner-Diagnostics: from know-smtprelay-omc-7.server.virginmedia.net by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.1/25703. spamassassin: 3.4.2. Clear:RC:0(80.0.253.71):SA:0(-2.0/5.0):. Processed in 3.667319 secs); 01 Feb 2020 19:29:08 -0000 X-Envelope-From: p.w.stephenson@ntlworld.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at _smtprelay.virginmedia.com designates 80.0.253.71 as permitted sender) X-Originating-IP: [86.16.88.158] X-Authenticated-User: p.w.stephenson@ntlworld.com X-Spam: 0 X-Authority: v=2.3 cv=Is0wjo3g c=1 sm=1 tr=0 a=MiHCjVqLJ44lE3bxSlffFQ==:117 a=MiHCjVqLJ44lE3bxSlffFQ==:17 a=jpOVt7BSZ2e4Z31A5e1TngXxSK0=:19 a=IkcTkHD0fZMA:10 a=Ye9q-bpsAAAA:8 a=fQM4lWy8w9BZKaIrGbQA:9 a=QEXdDO2ut3YA:10 Message-ID: Subject: Re: [bug] errexit and cmdsubst after "else" From: Peter Stephenson To: zsh-workers@zsh.org Date: Sat, 01 Feb 2020 19:28:20 +0000 In-Reply-To: <20200201175636.u4drsthh574p5cia@chazelas.org> References: <20200201175636.u4drsthh574p5cia@chazelas.org> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-CMAE-Envelope: MS4wfNXAGoTJXx2wgmstG2fENt7/piIEEq8OK1c5MZ+1KM+fMq2WwhU16SaQYtDoGPZFmaRSdt264i4VbzKvF02MmjNL/FVArv9rDM6lda9WtREBHoMRsA6X Qy86cWzubufJjiQhpAI9Eduuo1N7VHDSIGXFGthnuTLg1Hwg16xZHJLl On Sat, 2020-02-01 at 17:56 +0000, Stephane Chazelas wrote: > From > https://unix.stackexchange.com/questions/565158/command-substitution-does-not-respect-err-exit-sometimes > > $ zsh -ec 'if false; then;else a=$(false); echo $?; fi' > 1 > > expected no output because of errexit. The following passes all tests; I hope we've been diligent in adding test cases for previous failures as bug ping pong is a fairly silly game... Obviously, please do run any other tests you feel may be relevant (and I will add them if we don't have them). pws diff --git a/Src/loop.c b/Src/loop.c index 538afb8dc..01abc6cc9 100644 --- a/Src/loop.c +++ b/Src/loop.c @@ -570,7 +570,7 @@ execif(Estate state, int do_exec) if (run) { /* we need to ignore lastval until we reach execcmd() */ - if (olderrexit) + if (olderrexit || run == 2) noerrexit = olderrexit; else if (lastval) noerrexit |= NOERREXIT_EXIT | NOERREXIT_RETURN | NOERREXIT_UNTIL_EXEC; diff --git a/Test/C03traps.ztst b/Test/C03traps.ztst index e661aabd5..6f84e5db2 100644 --- a/Test/C03traps.ztst +++ b/Test/C03traps.ztst @@ -500,6 +500,15 @@ >Succeed 2 >Succeed 3 + (set -e + if false; then + else + a=$(false) + print This should not appear + fi + ) +1:ERREXIT is triggered in an else block after a cmd subst returning false + fn() { emulate -L zsh setopt errreturn