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 c...@case.edu http://cnswww.cns.cwru.edu/~chet/