[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: here-documents in $(command) substitution
From: |
Eduardo Bustamante |
Subject: |
Re: here-documents in $(command) substitution |
Date: |
Sun, 27 Nov 2016 11:51:57 -0600 |
Hi Alexey,
Please read the specification of here-documents in the standard:
http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_07_04
Quoting the relevant parts:
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>
characters in between. Then the next here-document starts, if there is
one. [...]
[n]<<word
here-document
delimiter
Delimiter (in your case the three character string "EOF"), has to be
on its own line, with no leading or trailing blanks (or any other
characters). If bash 3.x used to behave different, it's because it was
buggy.
Hence, the proper way to do a here-document inside command substitution:
hp% cat hd
export foo=$(cat <<EOF
echo bar
EOF
)
echo baz
hp% bash hd
baz