Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Arithmetic Zero



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