title: loop variables stuck as constant when using sqlcmd
body: <p>While creating a bash script that calls <code>sqlcmd</code> for different variables in a loop, noticed it appears to be <strong>setting the loop variables that should update in the loop to be constant</strong> once it is called the first time (can tell that this is very likely the culprit by <code>continue</code>ing and later and later segments of the loop until got to the <code>sqlcmd</code> segction). Ie. if we loop through a list (of length L) of MSSQL Server table names with <code>sqlcmd</code>, the loop will just do, not L, but <em>infinite</em> iterations of the loop instructions <em>using only the first entry</em> in the list.  </p>
  
  <p>A minimal example is below:</p>
  
  <pre class="lang-sh prettyprint-override"><code>#!/bin/bash
  
  tables_list=$1
  
  while read -r line
  do
      tablecols="$line"
      IFS=',' read -a arr_tablecols &lt;&lt;&lt; "$tablecols"
  
      mssql_tablename=${arr_tablecols[0]}
  
      echo -e "\n\n\n##### Processing: $mssql_tablename #####\n"
  
      TO_SERVER_ODBCDSN="-D -S &lt;ODBC DSN name for mssql host&gt;"
      TO_SERVER_IP="-S &lt;my mssql host IP&gt;"
      DB="ClarityETL_test"
      TABLE="$mssql_tablename"
      USER=&lt;my mssql username&gt;
      PASSWORD=&lt;my mssql login password&gt;
  
      #uncomment to see that sqlcmd does in fact appear to be the problem
      #continue
  
      {
      echo -e "Counting destination table: $DB/$TABLE"
      sqlcmd -Q "PRINT '$mssql_tablename';" \
          $TO_SERVER_ODBCDSN \
          -U $USER -P $PASSWORD \
          -d $DB
      } || { echo -e "\nFailed to truncate MSSQL DB"; exit 255; } 
  
  done &lt; "$tables_list"
  </code></pre>
  
  <p>where the file being used as <code>$table_list</code> looks like</p>
  
  <pre><code>mymssqltable1
  mymssqltable2
  ...
  </code></pre>
  
  <p>(since the example just uses the <code>PRINT</code> command, the list could be mostly anything you want to use, really).</p>
  
  <p>This behavior is really weird to me and could not find anything mentioning this in the docs (<a href="https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-red-hat?view=sql-server-2017#create-and-query-data" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/sql/linux/quickstart-install-connect-red-hat?view=sql-server-2017#create-and-query-data</a>) (I'm on CentOS 7). If anyone knows what is going on here or any further debugging advice, please let me know.</p>