How can I add numbers in a Bash script?

For integers: Use arithmetic expansion: $((EXPR))num=$((num1 + num2)) num=$(($num1 + $num2)) # Also works num=$((num1 + 2 + 3)) # … num=$[num1+num2] # Old, deprecated arithmetic expression syntax Using the external expr utility. Note that this is only needed for really old systems.num=`expr $num1 + $num2` # Whitespace for expr is important For floating point: Bash doesn’t directly support … Read more