Bug 485664 - bash4 behavior change wrt here-documents inside of $(...)
Summary: bash4 behavior change wrt here-documents inside of $(...)
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: bash
Version: rawhide
Hardware: All
OS: Linux
low
medium
Target Milestone: ---
Assignee: Roman Rakus
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2009-02-16 03:48 UTC by Ralf Corsepius
Modified: 2014-01-13 00:08 UTC (History)
6 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2009-02-24 14:13:36 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Ralf Corsepius 2009-02-16 03:48:20 UTC
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 15:29:44 UTC
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 15:43:29 UTC
Ralf,
have you tried F-10 versions of other shells? Can you try rawhide versions?

Comment 3 Ralf Corsepius 2009-02-16 15:57:17 UTC
(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 16:13:55 UTC
Nevertheless this will not be changed in rawhide.

Comment 5 Ralf Corsepius 2009-02-16 16:22:20 UTC
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.