From: Dan Nelson <dnelson@allantgroup.com>
To: Mike Hernandez <sequethin@gmail.com>
Cc: Matthias Berndt <Berndt.Matthias@gmx.de>, zsh-users@sunsite.dk
Subject: Re: Airthmetic confusion...
Date: Mon, 16 May 2005 16:46:11 -0500 [thread overview]
Message-ID: <20050516214611.GA90284@dan.emsphone.com> (raw)
In-Reply-To: <3060c239050516135933fd2ff6@mail.gmail.com>
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@allantgroup.com
next prev parent reply other threads:[~2005-05-16 21:46 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-05-16 17:55 Meino Christian Cramer
2005-05-16 20:43 ` Matthias Berndt
2005-05-16 20:59 ` Mike Hernandez
2005-05-16 21:46 ` Dan Nelson [this message]
2005-05-17 1:19 ` Mike Hernandez
2005-05-16 23:39 ` Matthias Berndt
2005-05-17 3:13 ` Meino Christian Cramer
2005-05-17 3:48 ` Bart Schaefer
2005-05-17 11:26 ` Mike Hernandez
2005-05-17 14:57 ` Meino Christian Cramer
2005-05-17 3:14 ` Meino Christian Cramer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050516214611.GA90284@dan.emsphone.com \
--to=dnelson@allantgroup.com \
--cc=Berndt.Matthias@gmx.de \
--cc=sequethin@gmail.com \
--cc=zsh-users@sunsite.dk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).