On 9/13/20 4:51 PM, Robert Elz wrote:
> | The specific construct is
> |
> | P=A
> | cat <<EOF
> | ${P+\"$P\"}
> | EOF
>
> That should output \"A\"
OK, let's discuss it.
>
> | In this case, the usual proscription on double quotes in here-documents
> | does not apply, since the double quote appears within ${}.
>
> Huh? Where does that come from, at best a " inside a quoted ${} is
> unspecified. But in a here doc, " is simply not a quoting char at all.
"However, the double-quote character ( '"' ) [edited, since the HTML on the
web site is malformed] shall not be treated specially within a here-
document, except when the double-quote appears within "$()", "``", or
"${}"."
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_07_04
That implies that the double quote *is* treated specially when it appears
within a ${} expansion inside the body of a here-document, so the backslash
quotes it. The question is how special [insert eye-roll emoji], and what
rules you follow. It seems like shells follow the double-quoting rules if
they follow any.
(There's also whether or not the double quotes in the above text are
grammatical or syntactically significant.)
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU [email protected] http://tiswww.cwru.edu/~chet/