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 13097 invoked from network); 6 Nov 2022 20:46:20 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 6 Nov 2022 20:46:20 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1667767580; b=mx6N9/+JvmHZjzPR41IL58KIT/c+304YVbijD5EnGVIgL1/YaVfvIkcSqwPoOUg7gSXM5g1OLJ CE7vUTmahiXTBiIBMKpcfmCokpnKqxRFrAnqAcdRxHRnbMmNnuqpGaoMGF18dpIO/U3MgiwM8u dW89EpSJSzp0bnP1IBPRsUFylf7ktCV9MlBqVVbZjc38xuZcLYsBCg5C34rXFq1yCtGf4eqJ2i iQ5X3usq4vTVqjnzehxtR7jFAwJDDlEwPWzdBpeT8pjBfb1D0P1V/kKy1F4Q9d30TwV0QH5O5e 2fCDISzfiPCrgpEAKyi855MbPz5FfWEem1FAzW3bEu9yGQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f41.google.com) smtp.remote-ip=209.85.218.41; 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=1667767580; bh=nvGoG3D9uubLKFqNv5sIrBn1MHXZpKD8cPhxSYF52Yw=; 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=JgJvZlFFvxVnKXy1ZgPZY7efDQrlxNkR/mIh9zbbbNuA+b3/WnzsZBqUWSZcm4WRySIrTRfkbL tlCGDH9ZfESwjYb1ctxXjkNAsghdDBszxSKLDLPLv7mMEnCGDKkbcHQbofzPdDmY4WWC/FZRBE qH6MnruxrVcNGSsTp+ZqB0KRFMI+jwjKv0WA3451CsWtE4kQg4rvIcoekuJr+77V7AV5EQz9tr YuGKybhxdfQHolvCIvIBtnUuG1o2/MfRuhzRVHNtDnwmNfrWPRAsSNQ8J7LWMZPGRcHoGiH/hR itkKEjtrgfvunKQsbvB2l4SONuUfn4VZ0X2DJiHOEhy8xQ==; 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=RgtuXWpD/TXMeAc4h1F5cCnkHWpjqpzg/vdQW8Urwl0=; b=LEl5AyTxxzn5UDziABoOEFXWMF gcnnQELfymhFM86xKjo4bKhTnh/VfC3nYkyx0Xddr1IICFQafp+7vEyVWmYJ9OawzKQPGSTqlXIdU l7Q5RteEm8Ef+H8Gd9nQoFiRyFz6BLeECf83AgdUJHwLCj3kpkM46RIZe81o8JZkaYeYiQ4TCb1/j QY9Z+bo2tIRFdcf5CBylZnwHcI0jPtnPfKTjhl5JmEMrpATb7dYrkQbSJyMn9twWYYQ2W/Qf22oGX Npn1dYXOwgXYA8wTX3M8IvXJCijysrMMRegKbCuUeBhau2vh4jA7+xnooHjcsfthKQCzoeR7q0uE0 yOmRIT1w==; Received: by zero.zsh.org with local id 1ormX5-000DTQ-6Q; Sun, 06 Nov 2022 20:46:19 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f41.google.com) smtp.remote-ip=209.85.218.41; 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-f41.google.com ([209.85.218.41]:36549) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1ormWT-000D8H-Co; Sun, 06 Nov 2022 20:45:43 +0000 Received: by mail-ej1-f41.google.com with SMTP id 13so25482405ejn.3 for ; Sun, 06 Nov 2022 12:45:41 -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=RgtuXWpD/TXMeAc4h1F5cCnkHWpjqpzg/vdQW8Urwl0=; b=u5UroV2bwYqp7zPCYGWIsh1hH9Gnot3AiMR4UVrktx4jGo7NKddAE7PVPJTAMqjLMg Sux1K2thXHyb4x1yieO4PKFhTA3yjl/uVhKFj04CC+RjI+x6ljekFD8K/aUzoclu49hT SducTJJunkXiAhp3qu67pVB1sakcKfkVHtipmOXB3F6Aogc2cSuImtlRbBtUrYjI+Qbn GgHKJbY6EgvfNpsZ7VGPSvcdRQNMQDoDCOH4L1URhxF1M1ut2P++biyl9Joc2N8TUKmf Z8hRT5JNqFftPu6sEyxw+gd97wu4bNKsS+HRD1GdYlHa1GlHT3ZMx+r0Zkxfqy23hEkq GMDA== 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=RgtuXWpD/TXMeAc4h1F5cCnkHWpjqpzg/vdQW8Urwl0=; b=6/q2KpZo35rRpHHZHwhc94vN1NMWEez4YF0jm0lnRceUzG/a6dpsICyb+mo9yssbGN 3B5bCHb/gIvE1uIxQ5hWUSuLDZwE7MHfPklc1SneAllEYvq5jWJODoqT8pKvRKdTKOQ8 UiEiz/40vluNqPf2DF9lRWB9pScmLOAQ9Iov2hhCiQFRtSd5KJzDdY52EZ8zZK+qy0Ef rUNqhu+d7ieKg8z6lB6HDGWzJs2uqfSS4babtMasEAjQTTBm/towvd7OAC16nMBwgAaZ ww6nzembV2h6/61rMg2xkDnGBUtNHOmBkNMG0O/nmuyg9xCJ9YS41iT9CpseVFZjdpC2 f7lw== X-Gm-Message-State: ACrzQf05PshY7YYZPPdppbves19kWqvFTFRK/bkS9mmz/JGvZeVTwCFV teqbwp2ZFLIyzuol+RVQplJLl7CAKSPeg2697E0U+A== X-Google-Smtp-Source: AMsMyM7Jm3zlCBN855eLC0GR/xeRziqRZPdShOo78xTkPmmad9cgwSbMyTupjCjhHagGpT3ksVJrRQS7LVVLMG0Czpk= X-Received: by 2002:a17:906:58c7:b0:722:f4bf:cb75 with SMTP id e7-20020a17090658c700b00722f4bfcb75mr44246316ejs.450.1667767540736; Sun, 06 Nov 2022 12:45:40 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Bart Schaefer Date: Sun, 6 Nov 2022 12:45:29 -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: 50895 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 Fri, Nov 4, 2022 at 9:39 AM Philippe Altherr wrote: > >> function fun1() { >> { false && true } >> } > > [...] 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. [...] Apparanty Zsh simply = ignores non-zero statuses of conditionals if they weren't generated by the = last command. In fact, comment in exec.c says: * ERREXIT only forces the shell to exit if the last command in a && * or || fails. This is the case even if an earlier command is a * shell function or other current shell structure, so we have to set * noerrexit here if the sublist is not of type END. But execcursh() unconditionally sets this_noerrexit =3D 1. Does this act better? (Hopefully I don't need an attachment for this one-liner): diff --git a/Src/exec.c b/Src/exec.c index c8bcf4ee5..d11f79d90 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -451,7 +451,7 @@ execcursh(Estate state, int do_exec) cmdpop(); state->pc =3D end; - this_noerrexit =3D 1; + this_noerrexit =3D (WC_SUBLIST_TYPE(*end) !=3D WC_SUBLIST_END); return lastval; } All extant tests still pass. Does not affect how fun3 and fun4 behave, so I suspect this fix may be needed elsewhere ... there are a bunch of similar cases for multi-line shell constructs in Src/loop.c