From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 21133 invoked from network); 8 Nov 2022 05:37:16 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 8 Nov 2022 05:37:16 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1667885836; b=FuCPOfH28aGEniiR2cSqqNqQoYHRoleCCZcjMpPX49NKqwxZ2hNnH4h8uFpT7gBEnYO1Q2qB/7 b5+2mGRl9EAzGJeYSrgP3CjzkvWWffx+XZjxRkH9AMWxLGlGfdcEvxgF+tt/M0oMEuqB+YDhYc nkpMmGI/hymAyuQ9wDeINjZPlyXSGMRJXDyeP0id0mrHE3e8c2zDqkvTVHFhQhEB59uFnQSXbb sH+yl6Wg2AzvLmA9AxXZvS4scGCj9a19XAgZNeTQzP6zpTU7DKb6qqPatrskmAQy9OiJRhlmUP /K+jGZN0HTk3h5Lxhx4GgSzpHzVBqlX43gshGqa08YW2GQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f51.google.com) smtp.remote-ip=209.85.218.51; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1667885836; bh=32dLDW4DfBsXyT5ZkbDxrytefJSDKJWuFalSwPQZsSE=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature: DKIM-Signature; b=hG9Wi2dTWwk9bqaNT9WZBw5ivBOfSkJR3YmvyVF5xcKlyiwne5qNba0bseVgOl91fH1qHOg3qQ kvSEnMjfcLsnQxJLuRVXmQqgUnSGwKsBZhSBEgNBqaPRXPGOlqAKUfV8XBSdb69dSrpX0bW3hk sDJsK7VWle7sx+71z7xS7IB9qqDoXoTPl1tinM98GnhCnKSABvr0Tx+VDRwgbR9BI9Jz6Ewvxf mX46II4E7NJXBdbTzZltkvXlasGiNkkZY87OEJ99WbsPJyKlO3RYMBV2ctDbjwNB0Tz7GWpHsV 3AubFydJjy5xxUTlvWKWqwA91bBerZNBHQigNHAP6vAPEA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=5Zk4c+zjlJn6sOwqJl4oUn7s2hdaAsuP/iZAhfYLPjE=; b=dtaFBXSGFlyR9nsskbbqOsNKEq 3kbzWThUfgjmIJXa2SRS5o8HnFhEqRDfynZXtx9bGDYRTx+wIynY3UsisLbX52J4sJV9VLLCR5jZr YTKlz6v2t/BKyYiN5YBwatD2j4gO6/+GyNrYCpy87qunftdf7E8eeBWGr742VU1UU9YxJdmYYIVSf hnnBjJLAKhTVLVF+afLwbH02WCOg3fqAQGsV7TYLpX9OveQnDMaZFZbExPhV2vHKLGzSHAtowoR4U Ue/iJYI/xO6FKRFG6ow85xT/wsgqG1J2WqszfOR0yPYkyaF2udAoiCH1MRhiH+vLPTimqqbR08Djr /WULADAg==; Received: by zero.zsh.org with local id 1osHIR-00058Y-MD; Tue, 08 Nov 2022 05:37:15 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f51.google.com) smtp.remote-ip=209.85.218.51; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ej1-f51.google.com ([209.85.218.51]:46888) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1osHHe-0004ne-6W; Tue, 08 Nov 2022 05:36:26 +0000 Received: by mail-ej1-f51.google.com with SMTP id bj12so35628779ejb.13 for ; Mon, 07 Nov 2022 21:36:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=5Zk4c+zjlJn6sOwqJl4oUn7s2hdaAsuP/iZAhfYLPjE=; b=7mXtgNl9ndPdrni1ojXP2k9EJhv3A4CKD3oi53Rmn9vViLYEHYeZgIz9xEkFkA9uA8 /RilO7+wQAfulzRlWrXT9fSJbfaHO0pdrOyuwj2cD9HGR5VzVJmsaDvwLb1Mol/EHqoq F6tUX/UQD2XWCEG/SMDHwlmQSJNcdklaJgUhR84Cg85E8iDS2+LRtliRQlyaWK7kZvIQ 5TmUlTF7/H4fgZpbos/CDqMaXuV3MQrpwWU39t4AGEt8BF1KipTQsT/LOZsvCGCW9iqi HJGSFlY8Gj+JbaR2N0KPA26FbUWQE6h68gc2BD2YokDuKwZZmeUFlvMVyNiXExzOwHlK QSkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5Zk4c+zjlJn6sOwqJl4oUn7s2hdaAsuP/iZAhfYLPjE=; b=rlTUNYXAzB+pEiKW/Ewik7BKleMadZ/Iaviow04JqkYoan5W9JKN5euXhXpkn7sHez T3ligSTAtGKIIGoefQ5NLjQzv3vwWuIcqPTdkTIcFvJm5q6IXfz6qiTkBH1ZglZhgcZQ TufCTljXezNwHhOWfOiNXqTlAeuj9lwcpnxFRd8ybvzfZcm119qjTtsRnrWoCI2jISkp s90kDQNL7GDjErMxsgE595F40mHM2VLrQamUlR9VDjBeAUqiQOKS0Zoshjkv36Ee7rtf UTCLDYcTGSiw5VDIywMmh00OHRljjH0pRRnzh1e0mxQnl2r+WBbSpRZ0E3TtSVtgiFhq w1TA== X-Gm-Message-State: ACrzQf2iL3fAIF7It6Ha2L6IG+UcpZ7CFkZ/hg5Is2iB6iVgHWq+McPJ ioL89YQPe+9tlbV6tqa5Vw2d78XUYhq0bdwHkOfVGg== X-Google-Smtp-Source: AMsMyM6d0ndKiNNe1EW2iDuZh/v0heiqEr0KxMFEjH+whTrKn4bqYopuD1S18iy0E/1/EJsflpURkY/JtGyTrtSrF9s= X-Received: by 2002:a17:907:2c78:b0:7ad:8a7a:3749 with SMTP id ib24-20020a1709072c7800b007ad8a7a3749mr51472333ejc.55.1667885785580; Mon, 07 Nov 2022 21:36:25 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Bart Schaefer Date: Mon, 7 Nov 2022 21:36:14 -0800 Message-ID: Subject: Re: Inconsistent behavior of ERR_EXIT with conditionals To: Philippe Altherr Cc: zsh-workers@zsh.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 50912 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Mon, Nov 7, 2022 at 8:58 PM Philippe Altherr wrote: > > My understanding of ERR_EXIT is that it should trigger an exit of the she= ll immediately after any command returns with a non-zero exit status, with = the exception of commands whose exit status stands for a condition (for exa= mple in the condition of an if statement or on the left of an || operator).= In other words, when ERR_EXIT is enabled, any command that unexpectedly fa= ils should trigger an immediate exit of the shell. The key word is "unexpectedly". The output of bash 5.0 for your script (with minor syntax differences tweak= ed): Success-A Failure-a Success-B Failure-b Failure-c Failure-d Failure-e Failure-f So you can see that zsh agrees with bash on your "Failure" cases. The output of dash (as /bin/sh on ubuntu) is the same as zsh with the exception of Failure-b, which can't be tested because there is no equivalent of "declare" (or "local"). Bash disagrees with dash and zsh on your "Success" cases, at least at that version. The assumption is that anything between the keywords "if" and "then" (or between "while" and do" by the way) is a compound expression whose final result needs to be reached. The entire expression on either side of an && (or || ) is treated the same way, and the use of ! as "not" is similar -- in all of those cases, the fact that the programmer is explicitly testing an exit status is interpreted to mean that a failure is "expected". ERR_EXIT kicks in only when the result is not otherwise checked.