[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question about arithmetic logic.
From: |
Greg Wooledge |
Subject: |
Re: Question about arithmetic logic. |
Date: |
Mon, 18 Apr 2011 11:15:32 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Mon, Apr 18, 2011 at 10:57:00AM -0400, Steven W. Orr wrote:
> I get the same result as you when I do it your way. But if I add the
> typeset, I still get the same result:
>
> 515 > unset ss; typeset -i ss=1; ((ss)); echo $?
> 0
> 516 > unset ss; typeset -i ss=0; ((ss)); echo $?
> 1
>
> Interesting. So I redid my problem using unset:
>
> 521 > unset ss
> 522 > typeset -i ss=0
> 523 >
> 523 > (( ss ))
> 524 > echo $?
> 1
> 525 > unset ss
> 526 > typeset -i ss=1
> 527 > (( ss ))
> 528 > echo $?
> 0
>
> Why did this make a difference? What did the unset do?
What difference? I don't see any difference.
> It gets worse:
...
> It printed the correct values!
> Now let's try this differently. This time I initialize ss using a real
> integer value instead of hoping that the string gets converted to an integer
(more correct output)
> # One last time but without using unset
(more correct output)
> Does this mean that I have to go and check *all* of my code to ensure that
> integer initializations are being done using integer arithmetic expressions?
I'm confused -- you don't seem to be able to show the problem occurring.
I don't know what an "integer arithmetic expression" is, or at least, I
don't know what you think the difference between "1" and $((1)) is. They
are both the same thing: 1.
So, if you aren't seeing any difference between x=1 and x=$((1)) and
typeset -i x=1 and so on, why do you think you need to change your code?
> I'd say this is a big deal. No?
Only if you can reproduce the original problem. So far I haven't seen it.