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 32535 invoked from network); 8 Nov 2022 23:29:25 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 8 Nov 2022 23:29:25 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1667950165; b=cv32P0cnkL6UCLlrs6v5AJ9mawGNMmCqM6+yC/Ah0d+Rc7EUMQ269UdhX47NnvDtqhmYROyiKr A1wWYp+AgUsmvHUwJy8g5lVELPWPvZQvhy4BF5UhM/HvGZJSiv16FUDAFuMDuwl7bccevELIqp t/NL6yE/YDrJMV2b18zwf1fjIzyJpLyJp0T2QVUn4TJYl/vLqGAgn1PAZlVG3YexIUj96GBK1G F4hUCuXF/VLRGkgVM9fFlP4QQgTMhCj1Ma1zjcj3WMVwcEfUSfSJjXprYfQrkzXBB8ANhCRA8/ FKnDIwW0ubO9YJ7sMc4jqwHwSLpGR7OenVWawCXF9/NK+g==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f49.google.com) smtp.remote-ip=209.85.218.49; 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=1667950165; bh=aBKOGwjsVmfCcRIS7/xSJ904v6cp8O6l4+UQX0CCKM0=; 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=n5gcp5gwWB9YsN6StzyYUq16eJGQ+tv5hEPGakd/AwzhSt02FEiN/BAG6rP0bw1phd/BhqvX8F PaI3ub3em20qYVGQDKpBcV/qcPhF/pYtutGZfUMr2alZTKB0/sLjAgxkTesXBH97v5ML3jDpsy yQoCuF8WlcWHGU0fjQJGPGNeqsFCTQhAayKtmAQa49z4PIgqzY+hrkBLnWSsWsBb+57nbiw6JU o/E7CW6EJx5rzsQeGDaFHk/44uPDTCj2OKei6SW0H3U2+ssKXLKUrwQp3czuSzZqDJlp4FBNrm uZSNbT1mDBHf0o8yEnxwa1A8cebqnHUR4gOaQwlKS3gmXg==; 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=FBpXjdIvDUpdSeVMoRD5Mdtx4p+m8KZG+kUPSN2zRwI=; b=VwhyeZutHVLuKHUAP/OS2PQONT P0gaFR+En45W1SSy7fb8+Y8xLb0NqgvNaHdqgfo5tH1+0zc4aSVGMENOehwTEQPSM2F+HGoiQVpYi 139NZgMLnFdWYa7j1hfpQVlV/eTCUUnKlrRQxhRv+Vbr8Hr8/exR2/FlVlv9J4fpqDhlpH0cqLYNL 0wIx8tvLbCFfQQsqm+1sgitqfd/+vuOCYe6aCnft3V1/V6sK+oZVMvBioOC98o5TIHaFuIbNnVc6k tIjiIENASpiOkd+Hsa1MPGqPfwiXxXbPY3ANjA3DXpeUF42O5+0N+5jCZgfzt1ejocVrvgin1df+2 xb/vkMMg==; Received: by zero.zsh.org with local id 1osY20-000JAA-UQ; Tue, 08 Nov 2022 23:29:24 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f49.google.com) smtp.remote-ip=209.85.218.49; 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-f49.google.com ([209.85.218.49]:41664) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1osY1k-000IoC-Ag; Tue, 08 Nov 2022 23:29:08 +0000 Received: by mail-ej1-f49.google.com with SMTP id t25so42490907ejb.8 for ; Tue, 08 Nov 2022 15:29:08 -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=FBpXjdIvDUpdSeVMoRD5Mdtx4p+m8KZG+kUPSN2zRwI=; b=x+QYIWRCMJ3SYPGQ+24pilW2lOO6O2Ng5szwkCIjIHDMAGSEMCcr0HtAu/S3d7QEO5 5Ix8xGEc1+5rBBsAfTgobUnJSiR0RppvjDjGP0dAaI6TNg6SS/ZR7E8iSw1Q3DNM9ht7 7ffnex/XiBEbFHOhMINrmRDGhVY7M5LSqAppyN/hlYFqfX9KwkKfURseHXQ/p3DIUq5p sW5BgTTxKY7vg/opsWUtNhET+1h5rHWN17akUm24td6i23W641cskhe94F8wdzSQFomA A+CwrkMspfA2aoBkSxl+LStNgzS1K3ssVIB8fKkxuCIHyg7MSx6ZZtnmo7MAvoedY+O7 E6Rw== 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=FBpXjdIvDUpdSeVMoRD5Mdtx4p+m8KZG+kUPSN2zRwI=; b=ojwJRxWMATfpPR1RShwh6nrIfEWeeIzvnZo9DItCe4qk6Fg0nSHLwugqbzT3v3FUMQ rNsDxi2frt0aLnVVuHYVA0Q4QdMQQgUhfLQ5x0h5NSk0vqWUXqVy4Ul2CZPtPwsTDAZp ChzZOa+uLdknQz1I/gwHK4mCD6K0Il7x3QrdbGy6ppvOtkrvv8o0nymU2e7ktM1ARpgp PxK5HpOXcpv+NL8mNocvSm2xqKyhnigJcUQ5aqX/veBA8V1AhwU9PiaFolJgAimD9NF0 KDx21xq10l5Fj3DAgwqhPu45kuv14sZtcYzqKOjzzLIUsUkrtirmck/hdEzlJ6Py0iFg uhJQ== X-Gm-Message-State: ACrzQf0/zlQ3Sb+CFSHvsq8hQ9pklGgNUVdA6tKqnBHU7BiFbkqg5Uqj y5DmJsScAU9YZhDAKS5GSGj9AtyIUyoxG1AExs8d++BjXBo4aQ== X-Google-Smtp-Source: AMsMyM6/t1ATI6cObaIq5vdcaveP8kyWFyRV7UoebNc4yshaT12Tsgfg1OGVKRQtFhxpkAjUUFOlJKvHFS4PyxQYNUA= X-Received: by 2002:a17:907:2c78:b0:7ad:8a7a:3749 with SMTP id ib24-20020a1709072c7800b007ad8a7a3749mr55216461ejc.55.1667950147923; Tue, 08 Nov 2022 15:29:07 -0800 (PST) MIME-Version: 1.0 References: <1edb7786-f0b2-4830-88fa-99a19bda39e2@app.fastmail.com> In-Reply-To: From: Bart Schaefer Date: Tue, 8 Nov 2022 15:28:56 -0800 Message-ID: Subject: Re: Inconsistent behavior of ERR_EXIT with conditionals To: Philippe Altherr Cc: =?UTF-8?Q?Lawrence_Vel=C3=A1zquez?= , zsh-workers@zsh.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 50917 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 Tue, Nov 8, 2022 at 10:51 AM Philippe Altherr wrote: > > Let me try to illustrate with a more concrete example why I think Zsh's b= ehavior could/should be improved. Consider that a first developer wrote the= following code: > >> #!/bin/zsh -e The first developer is wrong. That's not what -e is for. A script should be correct WITHOUT the use of -e ... the purpose of -e is to uncover cases where the developer made a mistake, not to be an integral part of the script function. > On Tue, Nov 8, 2022, at 12:36 AM, Bart Schaefer wrote: >> >> ERR_EXIT kicks in only when the result is not otherwise checked. > > Unfortunately there are several cases where Zsh doesn't behave like that.= For example, consider the following commands: > >> { false; true } || true; echo $? >> if false; true; then echo 0; else echo 1; fi Again, wrong. "{ false; true }" is a single statement because of the braces. When that statement is followed by || the result of the ENTIRE statement is considered to have been "checked". Similarly, in "if false; true; then" the conditional part is considered as a single statement whose result is "checked". As Lawrence has said, you're discarding the POSIX definition of how "set -e" is intended to work. > There are other cases where ERR_EXIT is triggered but fails to propagate.= A major offender in that regard is the following code: > >> local var=3D$(false); echo $? > > In this case "false" triggers an ERR_EXIT but it only exits the sub-shell= of the command substitution. This is explicitly called out in the documentation: Unlike parameter assignment statements, typeset's exit status on an assignment that involves a command substitution does not reflect the exit status of the command substitution. Therefore, to test for an error in a command substitution, separate the declaration of the parameter from its initialization: # WRONG typeset var1=3D$(exit 1) || echo "Trouble with var1" # RIGHT typeset var1 && var1=3D$(exit 1) || echo "Trouble with var1" > However, having to systematically use this style is rather cumbersome. Fu= rthermore it's not even foolproof. Indeed, if there are multiple command su= bstitutions, the assignment returns the exit status of the last one. Thus, = the following command does NOT exit and prints "0": > >> local var; var=3D$(false)$(true); echo $? This also follows bash and presumably POSIX behavior. > Is there any chance that Zsh could be changed to more closely follow the = specification above? No.