ksh88 changing single quotes to double quotes inside heredocs? ksh88 changing single quotes to double quotes inside heredocs? shell shell

ksh88 changing single quotes to double quotes inside heredocs?


Here are my notes when I discovered this same bug several years ago.

Test script:

#!/bin/kshcat <<EOF  $PWD "$PWD" '$PWD'EOFecho `cat <<EOF  $PWD "$PWD" '$PWD'EOF`echo $(cat <<EOF  $PWD "$PWD" '$PWD'EOF)

Output for different shells:

  • Linux KSH Version M 1993-12-28 q
  • Linux Bash 3.00.15(1)

(NOTE: works as expected)

 /home/jrw32982 "/home/jrw32982" '/home/jrw32982' /home/jrw32982 "/home/jrw32982" '/home/jrw32982' /home/jrw32982 "/home/jrw32982" '/home/jrw32982'
  • AIX Version M-11/16/88f
  • Solaris Version M-11/16/88i

(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:

  1. Compute the single-quoted string externally from the here-file

    abc=xyzSTR="'$abc'"x=$( cat <<EOF  $abc "$abc" $STREOF)
  2. Use the here-file in a function instead of directly

    fn() {  cat <<EOF    $abc "$abc" '$abc'EOF}abc=xyzx=$(fn)