Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Arithmetic Zero
On Mon, Mar 4, 2024 at 7:28 PM sergio <sergio@xxxxxxxxxxxxx> 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).
Messages sorted by:
Reverse Date,
Date,
Thread,
Author