On Sat, Sep 30, 2017 at 03:38:00AM +0200, Martijn Dekker wrote:
> Op 29-09-17 om 14:16 schreef Stephane Chazelas:
> > 2017-09-29 11:59:52 +0200, Martijn Dekker:
> > [...]
> >> * BUG_HDPARQUOT: Quotes within parameter substitutions in Here-Documents
> >> aren't removed. For instance, if 'var' is set, ${var+"x"} in a here-
> >> document erroneously yields "x", not x.

> > Is that specified?

> As far as I know, is not specified that they should act any differently
> just because they're in a here-document, so I think by default that
> should be considered a bug. (The only other shell I've found that acts
> like this is FreeBSD sh, which is otherwise nearly bug-free.)

The expansion of here-documents is described as follows in XCU 2.7.4
Here-Document:

] If no part of word is quoted, all lines of the here-document shall be
] expanded for parameter expansion, command substitution, and arithmetic
] expansion. In this case, the <backslash> in the input behaves as the
] <backslash> inside double-quotes (see Section 2.2.3). However, the
] double-quote character ('"') shall not be treated specially within a
] here-document, except when the double-quote appears within "$()",
] "``", or "${}".

This text clearly defines things like

cat <<EOF
$(ls -ld -- "$v") `ls -ld -- "$v"` ${w#"*"}
EOF

the same way

a="$(ls -ld -- "$v") `ls -ld -- "$v"` ${w#"*"}"

are defined.

However, things like "${a-"*"}" are unspecified (in practice, the
asterisk may either be literal or generate pathnames, depending on the
shell). With

cat <<EOF
${a-"*"}
EOF

the same problem occurs. It is unspecified what the interpretation of
the characters between the double-quotes is. For example, ksh93 will do
tilde expansion within a here-document when ${a-"${a-~}"} is used, the
same way it will do when "${a-"${a-~}"}" is used normally. In other
cases, special characters within the unquoted part lead to strange
syntax errors.

Given that and the behaviour of the Heirloom Bourne shell (which also
keeps the quotes), I think it is valid to keep the quotes.

-- 
Jilles Tjoelker

Reply via email to