How to compare two floating-point values in shell script

Posted by Reem on Stack Overflow See other posts from Stack Overflow or by Reem
Published on 2010-05-04T23:39:43Z Indexed on 2010/05/04 23:58 UTC
Read the original article Hit count: 283

I had to do a division in shell script and the best way was:

result1=`echo "scale=3; ($var1 / $total) * 100"| bc -l`
result2=`echo "scale=3; ($var2 / $total) * 100"| bc -l`

but I want to compare the values of $result1 and $result2

Using if test $result1 -lt $result2 or if [ $result1 -gt $result2 ] didn't work :(

Any idea how to do that?

© Stack Overflow or respective owner

Related posts about linux

Related posts about bc