[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Question about arithmetic logic.
From: |
Steven W. Orr |
Subject: |
Question about arithmetic logic. |
Date: |
Mon, 18 Apr 2011 10:30:35 -0400 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 |
I happen to be running
GNU bash, version 4.0.35(1)-release (x86_64-redhat-linux-gnu)
I create an integer variable and assign it either a 0 or a 1. The arithmetic
test always returns success regardless of value. For example:
typeset -i ss=0
(( ss ))
echo $? # Returns 1. Expected because it should be
# the same as (( ss != 0 )) No?
ss=1
(( ss ))
echo $? # Also says 1. Should this be 0 because it should be the
# success result same as (( ss != 0 ))
But if I use an operator...
ss=0
(( ! ss )) # Says 0.
ss=1
(( ! ss )) # Says 1.
So it seems to me that if I do not use the logical not operator, then the
arithmetic test is doing a test to see if the string value of ss is not null
(or something like that). Is this a bug? A feature? Or am I doing it wrong?
TIA
--
Time flies like the wind. Fruit flies like a banana. Stranger things have .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net
- Question about arithmetic logic.,
Steven W. Orr <=