473,387 Members | 1,859 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

test with "$integer"

why is it that when i used the value with zero,comparing two integers,it seems that i got the wrong ouput?

Please consider the ff:

#!/bin/ksh
echo "63918000009" > k
cat k
read x < k
(( aj=63918000009 ))
if
[ ! -d "$x" = "$aj" ]
then
echo "$aj"
elif
[ "$k" = "$aa" ]
then
echo "$aa"
else
echo "done"
fi
exit 99
--------------
OUTPUT:
63918000009
-506509431

********but if:***** consider the 000009 that i removed from the first script.

#!/bin/ksh
echo "63918" > k
cat k
read x < k
(( aj=63918 ))
(( aa=12346 ))
if
[ ! -d "$x" = "$aj" ]
then
echo "$aj"
elif
[ "$k" = "$aa" ]
then
echo "$aa"
else
echo "done"
fi
exit 99
-----------
OUPUT:
63918
63918

Thanks..
Jul 28 '07 #1
9 2851
Motoma
3,237 Expert 2GB
In the first $k and $aa are both unitialized. In the second, only $k is.
Aug 1 '07 #2
In the first $k and $aa are both unitialized. In the second, only $k is.

Hi Sir,


Don't Know exactly what you mean.but somehow i just figured it out. i'l give it a try.thanks..
Aug 3 '07 #3
This his how my question is about:

#!/bin/ksh
echo "1234567890" > k
cat k
read x < k
(( aj=1234567890 ))

if
[ ! -d "$x" = "$aj" ]
then
echo "$aj"

else
echo "done"
fi
exit 99
-----------
OUPUT:
1234567890


but when i added any number to my input "12345678901" which becomes 11 numbers it seems that the output doesn't print for any input of more than 10 numbers.

---------------
OUTPUT:
done
Aug 4 '07 #4
Motoma
3,237 Expert 2GB
I am not entirely familiar with ksh scripting, but when I try and load up the last script you posted, I got an error on the line that reads:

[ ! -d "$x" = "$aj" ]

What are you trying to test for with this line?
Aug 6 '07 #5
I am not entirely familiar with ksh scripting, but when I try and load up the last script you posted, I got an error on the line that reads:

[ ! -d "$x" = "$aj" ]

What are you trying to test for with this line?

Maybe you can remove the "! -d" from the syntax.

[ "$x" = "$aj" ]

--------------------------------------------------
I guess I'm having problem with zero (0).

sometimes when I have to compare it with the value 43918706 ,it doesn't give me true value. what i need to do is to cut 439187 and then cut 6 and then paste the result so i have the value 4391876, which doesn't have any zero.

Please consider the following. let say you have to input your value.


echo "input: \c" ----> my input is 4391876
read a
let x=4391876

if
[ "$a" = "$x" ]
then
echo "$x"
else
echo "wrong"
fi

OUTPUT
-------------
4391876

CASE #2:

echo "input: \c" ----> my input is 43918706
read a
let x=43918706

if
[ "$a" = "$x" ]
then
echo "$x"
else
echo "wrong"
fi

OUTPUT
-------------
wrong
Aug 6 '07 #6
Motoma
3,237 Expert 2GB
if you are sure that your input is going to be numbers, just use the -eq comparison.

[ $x -eq $aj ]
Aug 6 '07 #7
if you are sure that your input is going to be numbers, just use the -eq comparison.

[ $x -eq $aj ]
#!/bin/ksh
echo "input: \c"
read a
let x=6391800000706

if
[ "$a" -eq "$x" ]
then
echo "$x"
else
echo "wrong"
fi

*Try to use input ==>6391800000706
OUTPUT:
----------------
888664258
Aug 7 '07 #8
Motoma
3,237 Expert 2GB
Load up this script I wrote. Hopefully you will see where the error is occurring.

Expand|Select|Wrap|Line Numbers
  1. #!/bin/ksh
  2. echo "input: \c"
  3. read a
  4. let x="6391800000706"
  5.  
  6. echo "a = $a; x = $x"
  7.  
  8. if
  9. [ $a -eq $x ]
  10. then
  11. echo "Shell script comparison passed."
  12. else
  13. echo "Shell script comparison failed."
  14. fi
  15.  
  16. if
  17. [ $(echo "$a == $x" | bc ) -eq 1 ]
  18. then
  19. echo "bc variable comparison passed."
  20. else
  21. echo "bc variable comparison failed."
  22. fi
  23.  
  24. if
  25. [ $(echo "$a == 6391800000706" | bc ) -eq 1 ]
  26. then
  27. echo "bc numerical comparison passed."
  28. else
  29. echo "bc numerical comparison failed."
  30. fi
  31.  
  32.  
Aug 7 '07 #9
Load up this script I wrote. Hopefully you will see where the error is occurring.

Expand|Select|Wrap|Line Numbers
  1. #!/bin/ksh
  2. echo "input: \c"
  3. read a
  4. let x="6391800000706"
  5.  
  6. echo "a = $a; x = $x"
  7.  
  8. if
  9. [ $a -eq $x ]
  10. then
  11. echo "Shell script comparison passed."
  12. else
  13. echo "Shell script comparison failed."
  14. fi
  15.  
  16. if
  17. [ $(echo "$a == $x" | bc ) -eq 1 ]
  18. then
  19. echo "bc variable comparison passed."
  20. else
  21. echo "bc variable comparison failed."
  22. fi
  23.  
  24. if
  25. [ $(echo "$a == 6391800000706" | bc ) -eq 1 ]
  26. then
  27. echo "bc numerical comparison passed."
  28. else
  29. echo "bc numerical comparison failed."
  30. fi
  31.  
  32.  
---------------------------------------
Zero "0" is very sensitive in unix, so I thought about this while doing my script.:


echo "input: \c"
read a

if
[ $a = ' 6391800000706' ]
then
echo "6391800000706"
else
echo "wrong"
fi
Aug 10 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Vijay | last post by:
<xs:element name="product"> <xs:complexType> <xs:complexContent> <xs:restriction base="xs:integer"> <xs:attribute name="prodid" type="xs:positiveInteger"/> </xs:restriction>...
2
by: Peter Ignarson | last post by:
Hi, simple question Is there a syntax (other than the one below that is invalid) that will let me declare and initialize two variables at the same time (using VS 2003, 1.1) ? Thank you Pete ...
4
by: Supra | last post by:
value of type "Integer" cannot be convert to system.color Public Sub APIHighlight2(ByVal BgColour As Integer, ByVal FgColour As Integer) SelectionHighlightBackColour(BgColour) Dim rtb As New...
2
by: Supra | last post by:
value of type "Integer" cannot be convert to system.color. in procedure events: Function doColor(ByVal rtb As RichTextBox, ByVal a As String) Dim bColor, fColor, fgcolor, bgcolor As Integer .....
6
by: Ying Lu | last post by:
Hi, I have a question about alter a column's type in a postgreSQL table. For example, I have 10, 000 records in a table name "test", I'd like to change column "machineID" type from integer to...
7
by: moonman | last post by:
Hello all, I've just jumped into Python trying to develop X-Plane plugins. All was chugging along well until I tried to use math.cos() snippet: import math
10
by: JDT | last post by:
Hi, Can someone provide me an example that uses std::max_element() (probablly the predicate version) to return the max "absolute" integer in a vector? Your help is much appreciated. Tony ...
20
by: chutsu | last post by:
I'm trying to compare between pointer and integer in an "IF" statement how do I make this work? if(patient.id != NULL){ } Thanks Chris
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.