From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 3A45C25CA5 for ; Tue, 5 Mar 2024 08:28:29 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1709623709; b=UuyschcNsbjfpLgowL+r3ozMwlzRYsvCM5eT1Bglb1Hs0f20B7jqEB0fYMp5zELZd8ickupVdX s8rCDJB6kBLCUGjdT7gasMAB59vSKuFsIdC76emuvLSrR4a8dSjQavbjN0GihDTSlmM99dB2Mx Zs+/tOIveBjhB9ouSGHeY0cOnpnta/mR3VH+ZKnLm0Nh9BzsuWDWhWv5phzPLTzyOVCXGq+Wpg ZjO3XT+uSO/Rit9tRVE/0/OBN6LtvQZ3Hc/+dtB8I6JmklmJ2zy/EUgsXfscxv3H1GrpTv6trK NHo54z5jTcFqLTy6fJ2nk5mEoTUHrEGGUJbAv6eZrCQixQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lj1-f174.google.com) smtp.remote-ip=209.85.208.174; dkim=pass header.d=gmail.com header.s=20230601 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=1709623709; bh=Ni/fkpV6OOHmcPPabBI8Op9OA3s+u6ytW41GrlYidUk=; 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=RKs69X3//r/Exk8iWDIyS/Qe8ZaVY1tvKD+bGvjXbT7wMJrj/G8719K/Jxkc3n4BHRqZU2uym7 rXzS8DBIsZMSp3uYacHXDkR0u1DYKZ50/uiFlpxQh4caQDxbeqysphCUdHET9SPJmCWjsdrsGz mI0uumkCWsWQD9g8/1CXC54VXBZymqbo6D6F/RBqxLigZLAwpOGYEBG8oyDkNHH3o/3gE+3Txm Dsv//ms3N07gC62epFGpvO1o4qXQZIzafcATguth3+rGFQCDRixiyiiojcLG8kfZPafCHStW2v LQT/vYtGxyegvRLUfA9ckYmwWhYCWt5pG7I+mkqywdVzdQ==; 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=oJIi1ltseRId1q2CSrQHpmgsbFEAp71KRR0hcO2Z1+g=; b=lxaVU8L1N/X3F0AO2p85GCUK91 7/GRV59O94tnNq3Q+Fe6I9WIztF0DGxnBt9nGa5TucDcRic2iBhm8nlKBlLaw/aI+HEn3AoJqqOw0 JDgaksRM7Lv1AIbtCzavVtCIk2k9853wWD+62Ilr3gWbZX9gA6J3q5FAvt5vSn9sDYpJnbDWVoizI dXKqCbZ3/VyKqZPgj3/tpI0Dw82kxuBAyh/sPzK04gzhatRVGeg2fifk1dbNfRZjlGzHIph0H/lUE wt5APJBfhMEIpD19OMiBDrBHpJ6lVsdNzIsHJEgX7hd4jAezjmtR2ooOD0ZwpvRgjbt5qotuafEu5 3m070KgQ==; Received: by zero.zsh.org with local id 1rhPDx-000NGM-Jt; Tue, 05 Mar 2024 07:28:29 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lj1-f174.google.com) smtp.remote-ip=209.85.208.174; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lj1-f174.google.com ([209.85.208.174]:52458) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rhPC5-000MVh-Ra; Tue, 05 Mar 2024 07:26:35 +0000 Received: by mail-lj1-f174.google.com with SMTP id 38308e7fff4ca-2d28051376eso71857511fa.0 for ; Mon, 04 Mar 2024 23:26:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1709623593; x=1710228393; darn=zsh.org; 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=oJIi1ltseRId1q2CSrQHpmgsbFEAp71KRR0hcO2Z1+g=; b=j/YebPPF+0fWzsnHZB95fgbukwGn0lTh+S2q4DX93fBfd/YVH0nVmLRfZu8IxZgA8x uSts79pFt4dEV2aVTmP2gPG3yl83HEp+n6nTnPZL32byq7ltcYvr/HAff5KgFCo/6twf /NrN+e0H6PbwQQ80/VgIJcocdePpF7sVBX0xN6SdngBWroHhklpTkjzxEhX1R+ql7NGk M8LV87Wk0Bg0cI3ChsDn+aPiqsOQo9lThoaMgbju+S3vcY7hm05KucX+Wxew9FsrlMKf ZyjJTNtphY9hL0aMDiCuxh8/uBH08KJ8oSf4c1G8fW5M17U3DA6vupPJw430ZMxJ+hzA gaMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709623593; x=1710228393; 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=oJIi1ltseRId1q2CSrQHpmgsbFEAp71KRR0hcO2Z1+g=; b=tMNj2f8jR8JyGbYC/iUcycGYsVLw0DC6QyryHMY/KEvZUtZVP3w+lzASwN2ckp3tOU UYlIDNcOEK+rTZ4rfwjG8jDVwtiwODO1XmYMDKl7dh3JF4+bnwm4XBk5SMI6oyM2ljOd 5/h/Do7wYEmPxK40dN/un+GX8O4/Mjbk7fw5bEGrIVbtPKoxSYd+sPENAaFFbm1ydov+ MQNQ8VBCC7vh7fyKdQWih6TZ6K2+FV5iUSikkXfLit5dGTso1UCF//Eh2Z5FwTctZg4O d/eW4Ewk4L7+CtJyl0FRHYLuNFv1fIZ5lzvm4/Xwcr6Zx3NYju6EHFJXmbX5cyitvB+e WexA== X-Gm-Message-State: AOJu0YwnZ6YC1EC/bi7iVPSFbflume9fRWI4qwU5xfzHszPSczdzwWnH AIHtuf9h3HqmL0UFqxiJ1O9bO4qjidYUbdhUf534WNZs0EP1HvFITs8l/mKcdaNryctintAymXS hDLqlZA7+PAzeGW6WhjDjBdX0XNlcd4EoPVY= X-Google-Smtp-Source: AGHT+IHxvq8HYBn51sGMn4nTA7QIDc+orHb5whYAmwKzHd3gu+HVQsrkiZJUDldsK0RlTgYeV56taZoxKwoSAHLVfqg= X-Received: by 2002:a2e:868c:0:b0:2d3:4c74:10cf with SMTP id l12-20020a2e868c000000b002d34c7410cfmr538156lji.24.1709623592808; Mon, 04 Mar 2024 23:26:32 -0800 (PST) MIME-Version: 1.0 References: <47117922-e17f-44d1-8a2f-2cb4a9c53606@outerface.net> In-Reply-To: <47117922-e17f-44d1-8a2f-2cb4a9c53606@outerface.net> From: Roman Perepelitsa Date: Tue, 5 Mar 2024 08:26:19 +0100 Message-ID: Subject: Re: Arithmetic Zero To: sergio Cc: zsh-users@zsh.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 29719 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Tue, Mar 5, 2024 at 4:28=E2=80=AFAM sergio wrote: > > ``` > #!/bin/zsh -e > (( test =3D 0 )) > ``` > > 2. How to do arithmetic evaluation properly in zsh sripts? postpend with > || true When I end up in a situation like this, I use this pattern: (( expr, 1 )) Although the more general patterns works here, too: list || true I never use `set -e`, a.k.a. `setopt err_exit`, on its own, because its behavior within functions is counter to what I need. In fact, I don't think I ever wanted this option to behave the way it does in functions. Let me show what I mean. set -e false launch-missiles If you put these lines at the top level of a zsh script, launch-missiles won't execute because the previous command (false) fails. But if you put the same code in a function, this guarantee is lost. % zsh -fc ' foo() { set -e false print launch missiles } if ! foo; then :; fi foo || false foo && true print the end' The output: launch missiles launch missiles launch missiles the end This issue can be solved by turning on err_return together with err_exit. foo() { setopt local_options err_return err_exit false launch-missiles } Now, we can either handle errors from the function gracefully: if ! foo; then do-something fi Or we can let it take the default error handling action, which is to exit the script: foo In no case will the missiles launch. Roman.