title: ksh88 changing single quotes to double quotes inside heredocs?
body: <p>I seem to be running into an issue that's specific to ksh88 that's changing single quotes to double quotes, but only under certain situations involving heredocs and command substitution.</p>
  
  <p>Here's an example:</p>
  
  <pre><code>#!/bin/ksh
  
  # This example works correctly
  echo "Example 1:"
  cat &lt;&lt;EOF
  The 'quick' brown fox "jumped" over the lazy dog.
  EOF
  echo
  
  
  # This example is broken
  echo "Example 2:"
  var=$(cat &lt;&lt;EOF
  The 'quick' brown fox "jumped" over the lazy dog.
  EOF)
  echo "${var}"
  echo
  
  
  # This example works correctly
  echo "Example 3:"
  var=`cat &lt;&lt;EOF
  The 'quick' brown fox "jumped" over the lazy dog.
  EOF`
  echo "${var}"
  echo
  </code></pre>
  
  <p>And here's the output (note how Example 2 is different):</p>
  
  <pre><code>Example 1:
  The 'quick' brown fox "jumped" over the lazy dog.
  
  Example 2:
  The "quick" brown fox "jumped" over the lazy dog.
  
  Example 3:
  The 'quick' brown fox "jumped" over the lazy dog.
  </code></pre>
  
  <p>The <code>'</code> to <code>"</code> substitution seems to occur <em>before</em> the command runs.  In actual context, the heredoc is passing SQL to Oracle.  By changing <code>'</code> to <code>"</code>, strings are being converted to identifiers, thus breaking the SQL.  This can also be observed by enabling xtrace during execution of the above code.</p>
  
  <p>How can I prevent the <code>'</code> to <code>"</code> conversion in the above code snippet without using backticks?</p>
  
  <hr>
  
  <p><strong>Edit:</strong> The plot thickens.  Replacing the command substituion <code>$( ... )</code> with backtick notation doesn't replace the single quotes with double quotes.  So (optional) question two: why?</p>