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 comman
Here are my notes when I discovered this same bug several years ago.
Test script:
#!/bin/ksh
cat <<EOF
$PWD "$PWD" '$PWD'
EOF
echo `cat <<EOF
$PWD "$PWD" '$PWD'
EOF
`
echo $(cat <<EOF
$PWD "$PWD" '$PWD'
EOF
)
Output for different shells:
(NOTE: works as expected)
/home/jrw32982 "/home/jrw32982" '/home/jrw32982'
/home/jrw32982 "/home/jrw32982" '/home/jrw32982'
/home/jrw32982 "/home/jrw32982" '/home/jrw32982'
(NOTE: single quotes replaced with double quotes and variable not substituted)
/home/jrw32982 "/home/jrw32982" '/home/jrw32982'
/home/jrw32982 "/home/jrw32982" '/home/jrw32982'
/home/jrw32982 "/home/jrw32982" "$PWD"
Work-around:
Compute the single-quoted string externally from the here-file
abc=xyz
STR="'$abc'"
x=$( cat <<EOF
$abc "$abc" $STR
EOF
)
Use the here-file in a function instead of directly
fn() {
cat <<EOF
$abc "$abc" '$abc'
EOF
}
abc=xyz
x=$(fn)