Bug 485664 - bash4 behavior change wrt here-documents inside of $(...)
bash4 behavior change wrt here-documents inside of $(...)
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: bash (Show other bugs)
rawhide
All Linux
low Severity medium
: ---
: ---
Assigned To: Roman Rakus
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2009-02-15 22:48 EST by Ralf Corsepius
Modified: 2014-01-12 19:08 EST (History)
6 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2009-02-24 09:13:36 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Ralf Corsepius 2009-02-15 22:48:20 EST
Description of problem:

Fedora 11's bash (bash4) doesn't accept this script:
# cat bla.sh
#!/bin/bash
e=$(cat << EOF
contents
EOF)
echo "$e"

# /bin/bash ./bla.sh 
./bla.sh: line 2: unexpected EOF while looking for matching `)'
./bla.sh: line 7: syntax error: unexpected end of file

ksh and zsh do, dash also rejects it:
# /bin/dash ./bla.sh 
./bla.sh: 6: Syntax error: end of file unexpected (expecting ")")


On Fedora 10, all of sh, bash, ksh, zsh process this script, dash issues an error as above.

Question: Is this simply a behavioral change having been introduced to bash4 or is this a functional regression?

So far, I haven't further investigated and am not sure about it.


Version-Release number of selected component (if applicable):
bash-4.0-0.4.rc1.fc11.x86_64

Additional info:
Moving the ')' to the line following the 'EOF' makes this script functional again. i.e. using this:

#!/bin/bash
e=$(cat << EOF
contents
EOF
)
echo "$e"
Comment 1 Roman Rakus 2009-02-16 10:29:44 EST
This is expected behavior according to posix. Therefore this is bug in older bash.
Quotation from posix:
 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. Then the next here-document starts, if there is one. The format is as follows:

    [n]<<word
        here-document
    delimiter


Therefore in your first example is missing <newline> before `)'

In my eyes this is bug in previous version of bash and in ksh, zsh and any other?
I will add maintainers of these shells (tcsh, ksh and zsh) to CC.
Comment 2 Roman Rakus 2009-02-16 10:43:29 EST
Ralf,
have you tried F-10 versions of other shells? Can you try rawhide versions?
Comment 3 Ralf Corsepius 2009-02-16 10:57:17 EST
(In reply to comment #2)
> Ralf,
> have you tried F-10 versions of other shells?
Which shells else do you have in mind?

As mentioned in my initial report, I tried sh, ksh, zsh, dash and bash on both F11 (yesterday's rawhide, in chroots on F10/x86_64) and F10.

(In reply to comment #1)
> This is expected behavior according to posix.
OK, however ..., please note this is a /bin/bash script, 
not a supposed-to-be POSIX conforming /bin/sh script.

i.e. the POSIX-dialect of shell languages is largely irrelevant here. 
This is the "bash-dialect" -- Of course, bash has the liberty to change the "bash dialect", but then this change would be a backward incompatibile change ;)
Comment 4 Roman Rakus 2009-02-16 11:13:55 EST
Nevertheless this will not be changed in rawhide.
Comment 5 Ralf Corsepius 2009-02-16 11:22:20 EST
If you prefer to throw away ksh-incompatibility and to further add to the already long zoo of general shell incompatiblities ;)

Please, send a patch to upstream autoconf such this incompatibility can be documented in Autoconf.info's.

Note You need to log in before you can comment on or make changes to this bug.