title: Arithmetic with array elements in bash
body: <p>I'm using bash and trying to add all elements of an array that was created from a file.</p>
  
  <pre><code>while read line; do
      array=($line);
      sum=0
      length=${#array[@]}
      for i in ${array[@]:0:$length}; do
         sum=$[$sum+${array[i]}]   #&lt;--- this doesn't work?
      done
      echo $sum
  done &lt; $1
  </code></pre>
  
  <p>edit: 
  I should have been clearer why i want to use array splitting in for loop</p>
  
  <p>The input may be ------> david 34 28 9 12</p>
  
  <p>And I want to print ---> david 83</p>
  
  <p>So I would like to loop through all elements accept the first one. so i would use:</p>
  
  <pre><code>length=$[${#array[@]} - 1]
  for i in${array[@]:1:$length}
  </code></pre>
  
  <p>because of this i can't use:</p>
  
  <pre><code>for i in "${array[@]}"
  </code></pre>