Re: POSIX shell specification insight requested
On Tue, Mar 02, 2004 at 01:04:43PM -0500, Branden Robinson wrote:
> Is the following construction POSIXly correct?
>
> foo=$(cat <<EOF
> Foo bar baz quux.
> EOF)
>
> ash (and dash, which is derived from ash) choke on this, and seem to
> ignore everything on the same line as, but after, the here-document
> terminator word.
>
> bash (--posix) and (pd)ksh have no problem with it.
>
> I would be most grateful if someone access to the POSIX spec could
> provide some insight into this.
The current version of POSIX is available here:
http://www.opengroup.org/onlinepubs/007904975/nfindex.html
It says, in
http://www.opengroup.org/onlinepubs/007904975/utilities/xcu_chap02.html#tag_02_07_04:
The here-document shall be treated as a single word that begins after
the next <newline> and continues until there is a line containing only
the delimiter and a <newline>, with no <blank>s in between.
Thus I think I agree with dash here. I suggest this alternative
construction:
foo=$(cat <<EOF
Foo bar baz quux.
EOF
)
Cheers,
--
Colin Watson [cjwatson@flatline.org.uk]
Reply to: