number calculation in bash

computation efficiency rank:
(()) == let > expr > bc

1.(()) and let is bash buildin command, which can execute efficiently
2.expr and bc is system command, drain memory and low efficiency.
3.(()) let and expr can only do integer computation.
4.bc can do float computation.

(())

1
2
value=$((3*(5+2)))
((value++))

let

1
2
let "value=3*(5+2)"
let value++

expr

1
2
value=`expr 3 \* \( 5 + 2\)`
value=`expr $value+1`

bc

1
2
value=`echo "3*(5+2)" | bc`
value=`echo "$value+1" | bc `

number calculation in bash
https://rug.al/2013/2013-08-03-number-calculation-in-bash/
Author
Rugal Bernstein
Posted on
August 3, 2013
Licensed under