Chen Xie Chen Xie - 4 months ago 8x
Bash Question

Shell: how to evaluate an arithmetic expression with more than two operands

I have read several posts but they are talking about two operands

I have got the following expression that is to be evaluated:

sum = a / b * 100

In the bash shell, I can do:

bash-4.1$ a=5
bash-4.1$ b=10
bash-4.1$ sum=`expr $a / $b`
bash-4.1$ echo $sum

However, I cannot do:

bash-4.1$ sum=`expr $a / $b * 100`
expr: syntax error

result=$(echo "($a/$b) * $c)" | bc -l)

Try bc.

For integers: echo $(( 10 /5 *200 ))