LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash string comparison (https://www.linuxquestions.org/questions/programming-9/bash-string-comparison-407972/)

noir911 01-25-2006 05:24 PM

bash string comparison
 
My script takes user input and compare it with some values. It works fine when it compares against 0.00 or 10 or 100. But if the user input is something like "-0.009" it gives error - "integer expression expected in line 7 and 9" where it ought to print the number like -

your number is -0.009.

Here's the code -

Code:

if [ "$num" = 0.00 ] || [ "$num" -le 10 ]; then      # this is line 7
  echo "your number is $num"
elif [ "$num" -ge "100" ]; then                      # this is line 9
  echo "your number is greater than 100"
else
  echo "your number is $num"


macemoneta 01-25-2006 06:37 PM

For floating point operations, you need to invoke bc. See the Advanced Bash-Scripting Guide for examples.

Alternatively, you can use another scripting language.


All times are GMT -5. The time now is 02:39 PM.