title: Bash bc returns (standard_in) 1: parse error only when part of for loop
body: <p>I'm iterating through an array of integers <code>${startTimes}</code> (marker locations in an audio file, in samples) and using <code>bc</code> to convert those integers to milliseconds. I'm passing the results into a new array <code>${msValuesArray}</code>. If I run each array element one at a time it works fine. If I run it in a <code>for</code> loop:</p>
  
  <pre><code>for i in $(seq 0 ${#startTimes[@]}); do 
      msValuesArray+=($(bc &lt;&lt;&lt; ${startTimes[i]}/44.1))
  done
  </code></pre>
  
  <p>The resulting <code>${msValuesArray}</code> contains the expected results, but the terminal outputs <code>(standard_in) 1: parse error</code>. </p>
  
  <p>While I intend to use this in a shell script, and after reading other questions here I learned that adding <code>#!/bin/bash</code> to the beginning of the command avoids the parse error, I still don't understand the following: </p>
  
  <p>a) why does the manual passing of a <code>${startTimes}</code> element into <code>bc</code> work without the parse error while the <code>for</code> loop also works, yet outputs the parse error (outside of the shell script)?</p>
  
  <p>b) despite the parse error, I have the resulting array that I want. Should I ignore the error?</p>
  
  <p>c) when adding <code>#!/bin/bash</code> to the beginning of the commands (still outside of the shell script, just in the command line) why are the results inaccessible? (Entering <code>echo ${msValuesArray[@]}</code> returns an empty array.)</p>
  
  <p>d) While running inside the shell script, is the same error happening but just not printing to the terminal?</p>
  
  <p>Any help is appreciated. Thanks.</p>