title: Bash nested looping behaviour
body: <p>I'm having trouble with a nested loop. The code looks like this:</p>
  
  <pre><code>while IFS='' read -r line || [[ -n "$line" ]]; do
      num=0
      for i in $line; do
          eval a_${num}="\"$(echo $i)\""
          echo $a_0
          ((num=num+1))
      done
  done &lt; file
  </code></pre>
  
  <p>In the file there are many lines. Every line consists of 16 space separated values: 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16</p>
  
  <p>When I read each line in the file the first occurance of <strong>i</strong> should be set as the variable <strong>a_0</strong>  </p>
  
  <p>So when I echo this value, given there are <strong>two</strong> identical lines in the file it should read:</p>
  
  <pre><code>01
  01
  </code></pre>
  
  <p>However this is what happens:</p>
  
  <pre><code>01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  01
  </code></pre>
  
  <p>Instead of echoing twice it will iterate twice the number of values in the line - 16+16 times. What am I doing wrong here?</p>