title: Array arithmetic bash shell
body: <p>I have numerous(<strong>nTotal</strong>) number of files each with one column of length <strong>L</strong> of float numbers, I want to add entry in line i_th of all these file and at the end. Compute its average and standard deviation. 
  I first read each file. Then I try to add this array to a an array, which gives me a syntax error: <strong>(standard_in) 2: syntax error</strong>. I expect that <strong>suma[i]</strong> contains sum of all the entries on line i_th of all the files now. Then I find the average
  <strong>Edit</strong> I changed for loops as suggested.</p>
  
  <pre><code>for (( n= 1 ; n &lt; $nTotal; n++ ))
  do
  
     IFS=$'\n'
     arr1=($(./a.out filename | sed 's/:.*//'))
  
     for (( i= 1 ; i &lt; $L; i++ ))       
     do
         sum[i]=`echo "${sum[i]} - ${arr1[i]}" | bc`
     done
  done
  
  for (( i= 1 ; i &lt; $L; i++ ))  
  do
     ya=$(echo -1*${sum[i]} | bc)
     aveSum=$(echo $ya/$nTotal | bc -l)
  done
  </code></pre>
  
  <p><strong>Edit:</strong> ./a.out produces files with one column of float numbers.</p>
  
  <p>To find standard deviation though, I <em>again</em> read data files and store them in arrays (I'm sure this is not the smartest way of doing it but I couldn't think of anything else.). I also could not find the standard deviation using: </p>
  
  <pre><code>for (( i= 1 ; i &lt; $L; i++ ))  
   do
      ya=$(echo -1*${sum[i]} | bc)
      ta=$(echo $ya/$nTotal | bc -l)
  
      tempval=`echo "${arr1[i]} - $ta * ${arr1[i]} - $ta" | bc`
      val[i]=`echo "${val[i]} - $tempval" | bc`
   done
  </code></pre>
  
  <p>Here I get zero for <strong>val[i]</strong> elements, I can't figure what is wrong. I would really appreciate it if you can guide me for this problem.</p>