![]() |
| ||
| to convert string to integer value 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 |
| ||
| Re: to convert string to integer value 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. |
| ||
| Re: to convert string to integer value Does any one have the pseudocode for this problem?? If you do plaz contact me Thanx |
| ||
| Re: to convert string to integer value 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. |
| ||
| Re: to convert string to integer value 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.5This 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... |
| All times are GMT -4. The time now is 1:08 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC