We have had discussions about whether things like <<''EOF
contains "quoted characters" or not (yes, I believe, even though
there are no chars actually quoted there) and the text of the
standard has been adjusted to clarify this.

But there is a somewhat weird case that the shells (those for which
this works at all, which is a minority) differ about, that I don't
think has been considered before.

Consider

        X=3
        cat <<$((1+1))
        $X
        $((1+1))

That doesn't work at all in most shells, but in the ones that it
does, is the output expected to be "3" or "$X" ?

In bash, yash, and zsh, the answer is 3.  In ksh93, it is "$X".

Either answer is defensible.   There are no actual quote chars
(no \ no ' no " (no $' either)) in that end word, so if we're looking
for something that quote removal would alter, there's no quoting present.
Hence, when evaluated, the here doc is expanded, and $X turns into 3.

But arithmetic expansions are defined as being read with the contents
the same as a double quoted string, hence the 1+1 can be considered to
be quoted.   Under this interpretation, no expansion of the here doc
contents occurs, and $X is not expanded, so is output literally.

Which is correct, and why?

I'd like to make the NetBSD shell implement this kind of thing one day
(things that look like expansions in here doc end words, which we currently
simply issue an error when we encounter) but I need to know which answer
I should produce in that case.

kre

Reply via email to