title: Bash: while terminate early when reading from file
body: <p>I am trying to run a file that contains a sequence of commands/scripts to run with arguments, like:</p>
  
  <pre><code>ls /etc/
  cat /etc/hosts/
  script.sh some parameters 
  ...
  </code></pre>
  
  <p>This seems to work fine but in some cases the while loop will end prematurely. This seems to be the case only when the scripts it is executing contains SSH/SCP at the end. The code to read the file:</p>
  
  <pre><code>while IFS= read -r line
  do
      # Cut command and parameters
      IFS=', ' read -a parameters &lt;&lt;&lt; "$line"
      cmd="${parameters[0]}"
      unset parameters[0]
      runScriptAndCheckError "$cmd" "${parameters[@]}"
  done &lt; "$SCRIPT_FILENAME"
  </code></pre>
  
  <p>When using set -x:</p>
  
  <pre><code>+ checkError 0 'ERROR: script.sh failed'
  + '[' 0 -ne 0 ']'
  + IFS=
  + read -r line
  </code></pre>
  
  <p>It looks like there is no more input although there is still lines in the file. If I comment out runScriptAndCheckError "$cmd" "${parameters[@]}" then it does print a lot more lines.</p>
  
  <p>I am not sure what is wrong with this code. I'd be really helpful if someone could please help.</p>