I want to calculate a given string in Bash. For example, given the string
(1+4)*2
I want the answer
10
I tried:
read x
echo $[$x]
It works fine for integer arithmetic, but I realize that it isn't working for floating point numbers: with the string
x=1/2
running
echo $[$x]
yields 0
, but I want 0.5
.
What should I do to get over this problem?