I am trying hard to compare two floating point numbers within a bash script. I have to variables, e.g.
let num1=3.17648e-22
let num2=1.5
Now, I just want do a simple comparison of these two numbers:
st=`echo "$num1 < $num2" | bc`
if [ $st -eq 1]; then
echo -e "$num1 < $num2"
else
echo -e "$num1 >= $num2"
fi
Unfortunately, I have some problems with the right treatment of the num1 which can be of the "e-format". :(
Any help, hints are welcome!
This script may help where I'm checking if installed
grails
version is greater than minimum required. Hope it helps.It's better to use
awk
for non integer mathematics. You can use this bash utility function:And call it as:
How about this? =D