0

How to compare a number stored as string to an integer value in shell scripting? Here is what I have,

if [$temp -ge 2.5] then;

when I run the above code, it gives the error as "Integer Expression expected".
Here the temp variable contains the number "3.0" as a string, I want to compare the value of temp is greater or equal to the number 2.5.
How can I do it.

Please reply soon.

Thanks in advance.

Shiva

5
Contributors
4
Replies
5
Views
12 Years
Discussion Span
Last Post by mittelgeek
0

an interger is a whole number, with no decimal point. That is why it is telling you an integer is expected.

either the number 2.5 or 3.0 will cause it to fail.

0

Does any one have the pseudocode for this problem?? If you do plaz contact me

Thanx

0

Here's some code for C# that works:

You can use doubles to hold numbers with decimal places.

if [$temp.convert.todouble() -ge 2.5] then;

that should solve your problem.

0

Try putting quotes around 2.5 and $temp like so:

if ["$temp" -ge "2.5"] then;

otherwise set a variable equal to 2.5 and test that:

SOME_VALUE=2.5
if [$temp -ge $SOME_VAULE] then;

This may require quotes too so...

These suggestions are based on BASH shell scripting which is what this kind of looks like, so your mileage may vary...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.