Re: string comparison problem in bash 3.00



On 2006-01-25, Chris wrote:
> 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 line 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"

Read the error message. It tells you that an integer expression is
expected, not a decimal fraction. Bash does not use decimal
fractions, only integers.

--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
.



Relevant Pages