Adding elements of a bash array
I want to add the elements of a bash array together. I provide an example.
invalv=(1 1 1 1 1)
nval=5
Solution 1:
nval=0
invalv=(1 1 1 1 0)
for i in "${invalv[@]}"; do (( nval+=i )); done
printf '%s\n' "nval: $nval"