I am getting this error message: line 12: 470 + : syntax error: operand expected (error token is "+ ")
I still get my answer of 470 at the end but this error message display in the output and I cannot understand why. Can any one please explain?
Here is my code:
while IFS= read -r var
do
total=$(($total+$var))
done<"$input"
echo "The total is = $total";
echo
My final output each time:
line 12: 470 + : syntax error: operand expected (error token is "+ ")
The total is = 470
$varis empty in that last iteration of the loop. The file probably ends with a blank line$varis empty before using it${var}is undefined) you could default${var}to 0:${var:-0}