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.
Here's an example:
#!/bin/ksh
# This example works correctly
echo "Example 1:"
cat <<EOF
The 'quick' brown fox "jumped" over the lazy dog.
EOF
echo
# This example is broken
echo "Example 2:"
var=$(cat <<EOF
The 'quick' brown fox "jumped" over the lazy dog.
EOF)
echo "${var}"
echo
# This example works correctly
echo "Example 3:"
var=`cat <<EOF
The 'quick' brown fox "jumped" over the lazy dog.
EOF`
echo "${var}"
echo
And here's the output (note how Example 2 is different):
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.
The '
to "
substitution seems to occur before the command runs. In actual context, the heredoc is passing SQL to Oracle. By changing '
to "
, strings are being converted to identifiers, thus breaking the SQL. This can also be observed by enabling xtrace during execution of the above code.
How can I prevent the '
to "
conversion in the above code snippet without using backticks?
Edit: The plot thickens. Replacing the command substituion $( ... )
with backtick notation doesn't replace the single quotes with double quotes. So (optional) question two: why?