[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: POSIX shell specification insight requested

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.

I just dealt with a similar issue writing an ultra-portable shell script. 
The correct construction using the old backslash form is:

foo=`cat <<EOF
Foo bar baz quux.

Note that the closing backquote is on the *next* line.

I presume that the 'modern' form would be:
foo=$(cat <<EOF
Foo bar baz quux.

> 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.

Nathanael Nerode  <neroden at gcc.gnu.org>
US citizens: if you're considering voting for Bush, look at these first:
http://www.misleader.org/  http://www.cbc.ca/news/background/arar/

Reply to: