Re: string comparison problem in bash 3.00
- From: "Chris F.A. Johnson" <cfajohnson@xxxxxxxxx>
- Date: Wed, 25 Jan 2006 18:57:23 -0500
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
.
- References:
- string comparison problem in bash 3.00
- From: Chris
- string comparison problem in bash 3.00
- Prev by Date: Re: string comparison problem in bash 3.00
- Next by Date: echo a random filename in the cwd?
- Previous by thread: Re: string comparison problem in bash 3.00
- Next by thread: Re: string comparison problem in bash 3.00
- Index(es):
Relevant Pages
|