zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: sergio <sergio@outerface.net>
Cc: zsh-users@zsh.org
Subject: Re: Arithmetic Zero
Date: Mon, 4 Mar 2024 20:23:51 -0800	[thread overview]
Message-ID: <CAH+w=7ajHGSDi8pR5qb8k404UJ8ZybgXgyPdQ5PzvPRxccOm9A@mail.gmail.com> (raw)
In-Reply-To: <47117922-e17f-44d1-8a2f-2cb4a9c53606@outerface.net>

On Mon, Mar 4, 2024 at 7:28 PM sergio <sergio@outerface.net> wrote:
>
> I believe -e is best practices for scripts

Leaving opinions aside ...

> 1. What is the reason for returning 1 when an arithmetic evaluation
> succeeds but is zero?

(( ... )) is intended to be useful in tests:
  if (( status == 1 )); then ...

> 2. How to do arithmetic evaluation properly in zsh sripts?

Several choices.
  typeset -i test=0
  : $(( test = 0 ))
  printf -v x "%d" 0

Or (back to opinions) don't use errexit.  IMO it's a band-aid that
discourages properly testing exit status where you should.  Plus, it's
got several obscure bugs in all released versions of zsh, not fixed
until the current development version (as of late 2022).


  reply	other threads:[~2024-03-05  4:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-05  3:28 sergio
2024-03-05  4:23 ` Bart Schaefer [this message]
2024-03-05  5:02   ` Lawrence Velázquez
2024-03-05  7:09   ` Stephane Chazelas
2024-03-05  7:26 ` Roman Perepelitsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7ajHGSDi8pR5qb8k404UJ8ZybgXgyPdQ5PzvPRxccOm9A@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=sergio@outerface.net \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).