This is similar to question about getting the minimum/maximum of two numbers, but I'm interested to do the same with float numbers.
So basically I'm trying to use shell arithmetic expansion using the ternary operator, but it only works for the integers.
For example I'd like to take two numbers and subtract some number and check whether the result is above zero, if not, set it above zero.
This works great:
value=5 echo $(( $(bc <<< "$value - 10") > 0 ? $(bc <<< "$value - 10") : 1 ))
1 as expected.
However when I'm trying to convert it into float comparison, it does not work, e.g.
value=0.5 echo $(( $(bc <<< "$value - 0.8") > 0 ? $(bc <<< "$value - 0.8") : 0.1 ))
which gives the error:
-bash: -.3 > 0 ? -.3 : 0.1 : syntax error: operand expected (error token is ".3 > 0 ? -.3 : 0.1 ")
bc is returning the right float number:
$ echo $(bc <<< "$value - 0.8") -.3
I assume bash can't handle such float comparison.
Is there any simple workaround for getting min/max for the float numbers (as explained above)?