[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[ale] Bash question...



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