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.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 12118 invoked from network); 4 Nov 2022 16:38:28 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 4 Nov 2022 16:38:28 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1667579908; b=ly1uDCbjK14WDXRI5s214zuhTnl3P16lknLX3S6CxjgLqHnsbwt5AkaXZZuecwH9+/nfYJjJKJ D0DvSrSuYYbHJIMItv9SmwURQul7zDscHbrOwboot+uVhdtnCNX3ECXseXAlXFqQ29+Lcac65r Q4RXuH21IkysG9TzjDKyEnCKKTnIvkHLnyYvKT6qNyQYGWfd/LfsvKdxIz1teKzLRrHqL375Gr PRauibFASfoUIj6V1hqNc8OdK3xmbFxo6/N2lqck8QgVoBekN9roGb2Gj9dHKgenWzhYi0gL8y 48CS9GzLDwkCP48hjUslK/rTxQY8M+ebN/p7RBzO8nlXWg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-vs1-f41.google.com) smtp.remote-ip=209.85.217.41; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1667579908; bh=cLjJISz6tn9ZjVHXE4nMw/SdRevVx9QzQU0clrHOGlI=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:MIME-Version: DKIM-Signature:DKIM-Signature; b=EBhY6Q/0Oa7jinoRTRcKhtJNkyYAu9Jutuueuq11iOAJJk8kd3QFVpn3B2sHB/CRA0zMNGjWV9 DV6sMUDj/6K3qyEOl6CT018faMaPOKSNz6mjPhsUVSlGJ/h+BP0YJLgRkVhgWxfV2QWudrPZUb h1iWXhg94cSzyr9rMhjvSc6hLt6MpZPdM6KqpU5nr393msVbbf4/aHvmYSJYO9beSlsprmhlvi qiZwGV71P3d5yrpirB7UeW19Ou4Df8G+4irasYlIb+f7dFAc9C5Tk7GoEdHrvp+neFcNsmVwf6 qEWr2BsfkZUnahBp/KVtfCjjmYLu4yfGU6ZKSTVy6Z1Tfg==; 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-Type:To:Subject:Message-ID: Date:From:MIME-Version:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References; bh=NHfj11jfmOGZg5EyoCaMXSJqIWpFTxhpNTOwcaKo6d8=; b=ndOpXlbuE2g82PO60EntDH7DX8 rawKAgLA2JDDPWBK3U5na8uiXPb2OlHjJ2zIHItcpZl22+A48UJUFDTRZ2/1qdwG4hoP+919fxkao Q1lWQ/mvVIjFTPmz0gvFfh99MOCIuWhY7IWg5+KbkVnQ1hmnBCGwG4u6PbLrF1Za0F6ysqsn1TVcQ m9sLm5ObQdqHxrh1UmEvCpTj5B3Gj/04zIKriX00wzphoXqkELt6DWOvWteiAhvMNHj16/HQBCw20 lqR2L49eLjV+gwC84lGThgHHMZPsq/G9kpbIK9HbclRF56micxdzwOxX9CiwEYbpoUCYJJukM3RnY GTrt69Lg==; Received: by zero.zsh.org with local id 1oqzi7-0003nH-9Z; Fri, 04 Nov 2022 16:38:27 +0000 Authentication-Results: zsh.org; iprev=pass (mail-vs1-f41.google.com) smtp.remote-ip=209.85.217.41; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-vs1-f41.google.com ([209.85.217.41]:43797) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1oqzho-0003TG-4t; Fri, 04 Nov 2022 16:38:09 +0000 Received: by mail-vs1-f41.google.com with SMTP id l190so4976170vsc.10 for ; Fri, 04 Nov 2022 09:38:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=NHfj11jfmOGZg5EyoCaMXSJqIWpFTxhpNTOwcaKo6d8=; b=ORexjCk8odcrMjP5scH5SeRUcdlc68ChmJQzMbnK+JGn5XthusGrOYuKjLZYhjadg0 vDDMB+e2m1D8svHRiOQRml9YYoJCMOjeIFf9knIGQf30VehuvoFEmIysmwuLnRJGVQp0 nzRirRWLmTkWDZggGomsMhZbA1fiGKqd6aCSVuAda8JiaDxljCWLhXuWibMWjtd2TnqV hUU+KX8JscF6VoNjffB1IBFEGAbvyJK5drJlSxbMzxKJWwq8MaYVzRm++tDxLJqfWHxY 0qgvzdanGgXAlDf+Gov69kDQHgfiY2twfrevXS2A67cA8onHVpyuDQLQ/UsQnw+GcHmY NP+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=NHfj11jfmOGZg5EyoCaMXSJqIWpFTxhpNTOwcaKo6d8=; b=qKZTMJG5eTkKxt44GNNHw9rY0pBgTJjADGsmkJXczMwmRsrchl6B7yT5yahz71GEk2 +cnlVL2lau/EuN9k4HJeyLBzbs+CRfWRJwourtxIeA7+Ncab2o0g5sDrcABHrw1ah9BZ 6XxxKOxRGdxfGfd99unTMTYfTOH3B3BhJC3QyqljAcrhoW34QP8eiverc6W6SnhSNAFS e0z33Q0/2/+HAxd1cZuwJIpuy8Jy6mNY1iwUwtR77tMoowgqbmTGLLVreU1xQpvGnXzi PUbHTLgAnFBykB+FrJSEDmDsZYPcDUgWrsQl+cJrmBvLGxKDj8W2V2+5MIf5LRa7RHOy cDWw== X-Gm-Message-State: ACrzQf2Hjln+aqeVMnX02qw1BiUDwLdT9dWuomWSdE9a8kEE+x4yBxeC dDpnTCaBgk5XbUXjBuvTzziyOcR7msaSWNlpR23vVHyNT7g= X-Google-Smtp-Source: AMsMyM56aK+esp2/0j88bSNARKNgyaFGdOG+6cPHH1pwXNsSGvQP4tnJhlu1l7yTzimPJOAW3tCPKUOMGZcy4oCOSk8= X-Received: by 2002:a05:6102:2389:b0:3ad:5573:897e with SMTP id v9-20020a056102238900b003ad5573897emr9449377vsr.29.1667579886585; Fri, 04 Nov 2022 09:38:06 -0700 (PDT) MIME-Version: 1.0 From: Philippe Altherr Date: Fri, 4 Nov 2022 17:37:55 +0100 Message-ID: Subject: Inconsistent behavior of ERR_EXIT with conditionals To: zsh-workers@zsh.org Content-Type: multipart/mixed; boundary="000000000000c65d4905eca7b2fa" X-Seq: 50873 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: --000000000000c65d4905eca7b2fa Content-Type: multipart/alternative; boundary="000000000000c65d4705eca7b2f8" --000000000000c65d4705eca7b2f8 Content-Type: text/plain; charset="UTF-8" In the following code, the only difference between fun1() and fun2() is that in the former the expression "false && true" is within an extra set of braces but that's enough to make them behave differently. Calling the fromer doesn't trigger an exit while calling the latter does. #!/bin/zsh -e > > function fun1() { > { false && true } > } > > function fun2() { > false && true > } > > echo aaa: $? > false && true > echo bbb: $? > fun1 > echo ccc: $? > fun2 > echo ddd: $? > The output of the script (with Zsh 5.8 on Linux and Zsh 5.8.1 on macOS) is the following: aaa: 0 > bbb: 1 > ccc: 1 > The documentation of ERR_EXIT mentions the special case of conditional expressions. I understand that the command "false" by itself in the expression "false && true" shouldn't trigger an exit since it appears in a position where a condition is expected. However, since the expression "false && true" as a whole evaluates to a non-zero status and doesn't appear in a position where a condition is expected, I would assume that it should trigger an exit. Thus, in my opinion the script should have the following output: aaa: 0 > That's obviously not the case. Apparanty Zsh simply ignores non-zero statuses of conditionals if they weren't generated by the last command. However that doesn't explain why the call to fun1 doesn't trigger an exit. Like the call to fun2, it returns with a non-zero status but for some reason only the latter triggers an exit. Note that the following functions behave like fun1 and don't trigger an exit when they are called. function fun3() { > if true; then > false && true > fi > } > > function fun4() { > case foo in > * ) false && true;; > esac > } > And the following function behaves like fun2 and triggers an exit. > function fun5() { ( false && true ) > } > Philippe --000000000000c65d4705eca7b2f8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
In the following code, the only difference between fu= n1() and fun2() is that in the former the expression "false &&= true" is within an extra set of braces but that's enough to make = them behave differently. Calling the fromer doesn't trigger an exit whi= le calling the latter does.

#!/bin/zsh -e

function fun1() {
=C2=A0 =C2= =A0 { false && true }
}

function fun2() {
=C2=A0 =C2= =A0 false && true
}

echo aaa: $?
false && true=
echo bbb: $?
fun1
echo ccc: $?
fun2
echo ddd: $?

The output of the script (with Zsh 5.8 on Linux a= nd Zsh 5.8.1 on macOS) is the following:

aaa: 0
bbb: 1
ccc: 1

The documentation of=C2=A0ERR_EXIT mentions the spe= cial case of conditional expressions. I understand=C2=A0that the command &q= uot;false" by itself in the expression "false && true&quo= t; shouldn't trigger an exit since it appears in a position where a con= dition is expected. However, since the expression "false && tr= ue" as a whole evaluates to a non-zero status and doesn't appear i= n a position where a condition is expected, I would assume that it should t= rigger an exit. Thus, in my opinion the script should have the following ou= tput:

aaa: 0

That's obviously= not the case. Apparanty Zsh simply ignores non-zero statuses of conditiona= ls if they weren't generated by the last command. However that doesn= 9;t explain why the call to fun1 doesn't trigger an exit. Like the call= to fun2, it returns with a non-zero status but for some reason only the la= tter triggers an exit.

Note that the following fun= ctions behave like fun1 and don't trigger an exit when they are called.=

func= tion fun3() {
=C2=A0 =C2=A0 if true; then
=C2=A0 =C2=A0 =C2=A0 =C2=A0= false && true
=C2=A0 =C2=A0 fi
}

function fun4() {=C2=A0 =C2=A0 case foo in
=C2=A0 =C2=A0 =C2=A0 =C2=A0 * ) false &&a= mp; true;;
=C2=A0 =C2=A0 esac
}

A= nd the following function behaves like fun2 and triggers an exit.
=C2=A0
=C2=A0fu= nction fun5() {
=C2=A0 =C2=A0 ( false && true )
}
=C2=A0=
Philippe

--000000000000c65d4705eca7b2f8-- --000000000000c65d4905eca7b2fa Content-Type: application/octet-stream; name="bug.zsh" Content-Disposition: attachment; filename="bug.zsh" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_la2o0gck0 IyEvYmluL3pzaCAtZQoKZnVuY3Rpb24gZnVuMSgpIHsKICAgIHsgZmFsc2UgJiYgdHJ1ZSB9Cn0K CmZ1bmN0aW9uIGZ1bjIoKSB7CiAgICBmYWxzZSAmJiB0cnVlCn0KCmVjaG8gYWFhOiAkPwpmYWxz ZSAmJiB0cnVlCmVjaG8gYmJiOiAkPwpmdW4xCmVjaG8gY2NjOiAkPwpmdW4yCmVjaG8gZGRkOiAk Pwo= --000000000000c65d4905eca7b2fa--