From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14882 invoked from network); 16 May 2005 21:46:45 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 16 May 2005 21:46:45 -0000 Received: (qmail 88346 invoked from network); 16 May 2005 21:46:37 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 16 May 2005 21:46:37 -0000 Received: (qmail 25486 invoked by alias); 16 May 2005 21:46:30 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 8835 Received: (qmail 25473 invoked from network); 16 May 2005 21:46:30 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 16 May 2005 21:46:30 -0000 Received: (qmail 87352 invoked from network); 16 May 2005 21:46:30 -0000 Received: from dan.emsphone.com (199.67.51.101) by a.mx.sunsite.dk with SMTP; 16 May 2005 21:46:24 -0000 Received: (from dan@localhost) by dan.emsphone.com (8.13.1/8.13.3) id j4GLkBOb058091; Mon, 16 May 2005 16:46:11 -0500 (CDT) (envelope-from dan) Date: Mon, 16 May 2005 16:46:11 -0500 From: Dan Nelson To: Mike Hernandez Cc: Matthias Berndt , zsh-users@sunsite.dk Subject: Re: Airthmetic confusion... Message-ID: <20050516214611.GA90284@dan.emsphone.com> References: <20050516.195529.74749456.Meino.Cramer@gmx.de> <20050516224332.246839a4@localhost> <3060c239050516135933fd2ff6@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3060c239050516135933fd2ff6@mail.gmail.com> X-OS: FreeBSD 5.4-STABLE X-message-flag: Outlook Error User-Agent: Mutt/1.5.9i X-Spam-Checker-Version: SpamAssassin 3.0.2 on a.mx.sunsite.dk X-Spam-Level: X-Spam-Status: No, score=-2.6 required=6.0 tests=AWL,BAYES_00 autolearn=ham version=3.0.2 X-Spam-Hits: -2.6 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