Hi there.
I am trying to add every value in an array together in a single variable. The script is working, but throws an error:
syntax error: operand expected (error token is "+")
Is it not possible to add values from an array into a non-array variable?
Code:
echo Input some numbers, separated by a space please:
read -a choice
amount=${#choice[@]}
for a in `seq 0 $amount`; do
sum=$(($sum+${choice[$a]}))
done
echo The result after adding all numbers is: $sum
Thanks in advance.