bug-bash
[Top][All Lists]
Advanced

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

Re: here-documents in $(command) substitution


From: Chet Ramey
Subject: Re: here-documents in $(command) substitution
Date: Mon, 28 Nov 2016 13:56:18 -0800
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Thunderbird/45.5.0

On 11/27/16 2:12 AM, Alexey Tourbin wrote:

> Bash Version: 4.4
> Patch Level: 0
> Release Status: release
> 
> Description:
> Handling of here-documents in command substitution seems to be inconsistent.
> 
> $ cat test.sh
> export foo=$(cat <<EOF
> echo bar
> EOF)
> echo baz
> 
> $ bash test.sh
> test.sh: line 6: warning: here-document at line 4 delimited by
> end-of-file (wanted `EOF')
> baz
> 
> I see only two possibilities:
> 1) here-document is ended with the "EOF)" line, which also closes
> command substitution; then, bash should't have produced the warning;

The Posix standard is pretty clear about the rules for the here-document
ending delimiter: it has to exactly match the delimiter and be immediately
followed by a newline.  However, there is lots of existing practice, dating
back to the original Bourne shell, to allow the end of file to delimit a
here document.  Bash has always allowed the ending here document delimiter
to be immediately followed by the command substitution terminator, which is
why bash-3.2 didn't produce a warning with your example.  I got bug
reports about this silent acceptance, so I added the warning in bash-4.0.
The actual behavior didn't change; the only change was the addition of the
warning message.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]