> I've got a question about ksh and the use of quoting in a $( .. ) block:
> hithere="just testing"
> select foo
> from bar
> where baz='${hithere}';
> exit;
> EOF ) || exit 1
^
> What happens in this case is that sqlplus complains because it
> sees double quotes in its input, instead of single quotes. If I replace
> the $( ... ) with backticks ` it works fine.
> Am I doing Something Ugly(tm) here? I prefer to use a $( ... ) block,
> but how can I get the quoting right?
I think it most likely the issue you're encountering is due to the space
between EOF and ). You might also be encountering some additional
quoting issues.
Compare what occurs when I feed these different shell segments to ksh
(at least the version I have handy). If I use bash, I also get similar
results if there's no space between the EOF and closing ) or ` (and with
a space in there, results are slightly different, but also other than
what the code would imply was intended).
ksh input:
hithere="just testing"
output=$(cat <<EOF
baz='${hithere}';
EOF )
echo "$? $output"
ksh output (including stderr):
ksh: here document `EOF' unclosed
ksh input:
hithere="just testing"
output=$(cat <<EOF
baz='${hithere}';
EOF)
echo "$? $output"
ksh output (including stderr):
0 baz='just testing';
ksh input:
hithere="just testing"
output=`cat <<EOF
baz='${hithere}';
EOF `
echo "$? $output"
ksh output (including stderr):
ksh: here document `EOF' unclosed
ksh input:
hithere="just testing"
output=`cat <<EOF
baz='${hithere}';
EOF`
echo "$? $output"
ksh output (including stderr):
0 baz='just testing';
Note also that within here document, only command substitution,
parameter substitution and backslash quoting is done - all else is
passed literally. (These substitutions are suppressed if any part of
marker is quoted, and if <<- is used instead of <<, leading tabs are
stripped).
So, if you have shell script including:
hithere="just testing"
select foo
from bar
where baz='${hithere}';
exit;
EOF ) || exit 1
ignore precisely how and where your here document is terminated or if
it's missing termination) is:
select foo
from bar
where baz='just testing';
exit;
e.g. just testing gets substituted in place of ${hithere} and the rest
| << marker
| after reading the command line containing this kind
| of redirection (called a here document), the shell
| copies lines from the command source into a tempo-
| rary file until a line matching marker is read.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
ksh(1)
Caveat: your ksh mileage may vary.