I am having troubles with the arithmetic expressions in a bash file (a unix file .sh).
I have the variable \"total\", which consists of a few numbers separated by sp
There are a number of ways to perform arithmetic in Bash. Some of them are:
dollar=$(expr $dollar + $a)
let "dollar += $a"
dollar=$((dollar + a))
((dollar += a))
You may see more on the wiki. If you need to handle non-integer values, use a external tool such as bc.
Wrap arithmetic operations within ((...))
:
dollar=0
for a in $total; do
((dollar += a))
done