bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Yup!: Re: Incrementing variable=0 with arithmetic expansion causes Retur


From: L A Walsh
Subject: Yup!: Re: Incrementing variable=0 with arithmetic expansion causes Return code = 1
Date: Mon, 07 Sep 2020 15:18:56 -0700
User-agent: Thunderbird

On 8/28/2020 1:00 AM, Gabriel Winkler wrot
> # Causes error
> test=0
> ((test++))
> echo $?
> 1
> echo $test
> 1
>   
"((...))" is the "test form" for an integer expression.  That means
it will return true if the value of the interior, "...", of "((...))"
is non-zero and return false if ((... == 0)).  Remember "$?==0" == true
and "$?!=0" == false,

so if "..." is an expression then for:
   ...       is 0          is non-0
then
((...))      is false      is true
   $?        is 1          is 0

deciding that ((non-zero)) = true was consistent with most programmers'
expectations from other languages that 0 was false and non-zero was
true (which is opposite of the final value of "$?").






reply via email to

[Prev in Thread] Current Thread [Next in Thread]