I am working on bash script: need to evaluate an input and then output the result
as a float *.xxx:
I do:
read var1
var2=$((var1))
#echo $var2
echo $((var1))
an input: 5+503/20 + (192)/7
my output is 17 but it should 17.929
How to evaluate it as a float?
>Solution :
Bash only supports integer arithmetic.
In your case, you can use bc(1).
read var1
var2="$(bc <<<"scale=2;$var1")"
Use the scale variable in bc(1) to set the number of significant digits (default with is 0).