Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Airthmetic confusion...
- X-seq: zsh-users 8835
- From: Dan Nelson <dnelson@xxxxxxxxxxxxxxx>
- To: Mike Hernandez <sequethin@xxxxxxxxx>
- Subject: Re: Airthmetic confusion...
- Date: Mon, 16 May 2005 16:46:11 -0500
- Cc: Matthias Berndt <Berndt.Matthias@xxxxxx>, zsh-users@xxxxxxxxxx
- In-reply-to: <3060c239050516135933fd2ff6@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20050516.195529.74749456.Meino.Cramer@xxxxxx> <20050516224332.246839a4@localhost> <3060c239050516135933fd2ff6@xxxxxxxxxxxxxx>
In the last episode (May 16), Mike Hernandez said:
> If you set a variable to any integer other than 0, positive or
> negative, the return code is 0, which is successful exit, for example:
>
> (mike@mhernandez)(30/pts)(04:53pm:05/16/05)-
> (%:~)- (( r = -5 ))
> (mike@mhernandez)(31/pts)(04:53pm:05/16/05)-
> (%:~)- echo $?
> 0
>
> This occurs with a regular assignment as above, or if the assignment
> contains some variables (as in x = b - 4, if b was 4 the return code
> would be 1, yet the math is done and x is set to equal 0).
>
> There must be a reason why assigning 0 to a variable is considered an
> error (a reason which I could speculate about, but don't know for
> sure).
That's because within an arithmentic context, 0 is false and 1 is true,
so the following are equivalent:
true && echo true
(( 1 )) && echo true
(( 2 > 1 )) && echo true # since $(( 2 > 1 )) evaluates to 1
An assignment expression evaluates to the value of the variable, so
(( a=0 )) is the same as (( 0 )) .
--
Dan Nelson
dnelson@xxxxxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author