Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Arithmetic Zero
- X-seq: zsh-users 29717
- From: Lawrence Velázquez <larryv@xxxxxxx>
- To: sergio <sergio@xxxxxxxxxxxxx>
- Cc: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx>, zsh-users@xxxxxxx
- Subject: Re: Arithmetic Zero
- Date: Tue, 05 Mar 2024 00:02:42 -0500
- Archived-at: <https://zsh.org/users/29717>
- Feedback-id: iaa214773:Fastmail
- In-reply-to: <CAH+w=7ajHGSDi8pR5qb8k404UJ8ZybgXgyPdQ5PzvPRxccOm9A@mail.gmail.com>
- List-id: <zsh-users.zsh.org>
- References: <47117922-e17f-44d1-8a2f-2cb4a9c53606@outerface.net> <CAH+w=7ajHGSDi8pR5qb8k404UJ8ZybgXgyPdQ5PzvPRxccOm9A@mail.gmail.com>
On Mon, Mar 4, 2024, at 11:23 PM, Bart Schaefer wrote:
> On Mon, Mar 4, 2024 at 7:28 PM sergio <sergio@xxxxxxxxxxxxx> wrote:
>> 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 ...
Put another way, you can think of ((...)) as "translating" C's
notion of true/false into the shell's. C considers zero-valued
expressions to be false, so ((...)) "translates" them into an exit
status of 1, which the shell considers false/failing. Similarly,
C considers non-zero-valued expressions to be true, so for those
((...)) returns 0, which the shell considers true/successful.
--
vq
Messages sorted by:
Reverse Date,
Date,
Thread,
Author