bug-bash
[Top][All Lists]
Advanced

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

Re: cond?true:false and division by 0


From: Chet Ramey
Subject: Re: cond?true:false and division by 0
Date: Mon, 01 Aug 2011 20:47:20 -0400
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.18) Gecko/20110616 Lightning/1.0b2 Thunderbird/3.1.11

On 8/1/11 4:41 AM, address@hidden wrote:
>       Hello
> 
> I wanted to check a variable before attempting to divide something by it, so 
> I wrote :
> 
> echo $(( foo==0?0:something/foo ))
> 
> And bash 2, 3 and up to 4.2.10 version sent me a "division by 0" error.
> 
> So, I've tested a static version of the statement :
> 
> $ echo $(( 0==0?0:1/0 ))
> -bash: 0==0?0:1/0 : division by 0 (error token is " ")
> 
> It looks like the "division by 0" happens whatever the condition result.
> Shouldn't it happen only if condition result make the computing go that far 
> (like, FWIW, in zsh) ?

Hmm...this looks like a precedence problem.  I'll take a look.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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