[ale] Bash question...

Jim Popovitch yahoo at jimpop.com
Sun Jul 22 12:01:04 EDT 2007


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...




More information about the Ale mailing list