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?
You can compare floating-point numbers using
expr(1):You can also have
bcdo the comparisons as well as the calculations:Finally, ksh93 can do arithmetic evaluation
$(($result1 < $result2))with floating-point numbers, although bash cannot.