[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ale] Bash question...
- Subject: [ale] Bash question...
- From: yahoo at jimpop.com (Jim Popovitch)
- Date: Sun, 22 Jul 2007 12:01:04 -0400
- In-reply-to: <[email protected]>
- References: <[email protected]>
On Sun, 2007-07-22 at 10:37 -0400, Dr. Brian J. Dowd wrote:
> The value of $var is -4.865876
>
> if [ $var -lt "-4" ];
>
> throws an "Integer expression expected" error
>
The problem is that $var (since it isn't an integer) appears to test
("[") as a string. So the exception is due to passing a string to -lt
which is an operator only used for integer math.
I think the easiest way to make this work is to use bc (man bc). You
could do something like the following:
result=`echo "-4.865876 < -4" | bc`
if [ $result -eq 0 ]; then
echo "Equal or Greater Than"
elif [ $result -eq 1 ]; then
echo "Less Than"
-Jim P.
-------------- next part --------------
An HTML attachment was scrubbed...