Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 363371 - app-shells/bash-4.2_p8: here documents interpreted incorrectly within loops
Summary: app-shells/bash-4.2_p8: here documents interpreted incorrectly within loops
Status: RESOLVED FIXED
Alias: None
Product: Portage Development
Classification: Unclassified
Component: Core - Ebuild Support (show other bugs)
Hardware: All Linux
: Normal minor (vote)
Assignee: Gentoo's Team for Core System packages
URL: http://lists.gnu.org/archive/html/bug...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-12 19:52 UTC by Andrey
Modified: 2011-04-29 22:53 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments
emerge --info (emerge.info,12.30 KB, application/octet-stream)
2011-04-12 19:57 UTC, Andrey
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey 2011-04-12 19:52:30 UTC
Here document written within loops (or probably any other compound commands) in ebuilds are getting misinterpreted (compared to plain bash behavior).

Reproducible: Always

Steps to Reproduce:
1. Create a simple ebuild:
src_install () {
        for (( i = 0; i < 2; i++ )) ; do
                cat <<EOFF
${i}
EOFF
        done

        echo qqq
}
2. emerge it
Actual Results:  
>>> Install qqq-999 into /var/tmp/portage/test-bug/qqq-999/image/ category test-bug

qqq
>>> Completed installing qqq-999 into /var/tmp/portage/test-bug/qqq-999/image/

Expected Results:  
>>> Install qqq-999 into /var/tmp/portage/test-bug/qqq-999/image/ category test-bug
0
1
qqq
>>> Completed installing qqq-999 into /var/tmp/portage/test-bug/qqq-999/image/

The reason for this behavior is that src_install() gets clobbered in the environment:

src_install ()
{
    for ((i = 0; i < 2; i++ ))
    do
        cat;
    done  <<EOFF
${i}
EOFF

    echo qqq
}

The easy workaround is to add line "    :" after closing EOFF.
Comment 1 Andrey 2011-04-12 19:57:12 UTC
Created attachment 269697 [details]
emerge --info
Comment 2 Zac Medico gentoo-dev 2011-04-13 00:51:21 UTC
If you source the ebuild in a bash shell and then use declare -fp (as portage does) or declare -f src_install to view the function, then you'll see that bash itself is the source of the function corruption.
Comment 3 SpanKY gentoo-dev 2011-04-13 03:39:11 UTC
seems like a simple variant of bug 310197.  simple test case:
f() { for (( :; :; )) ; do
cat <<EOF
EOF
done; :; }
type f

seems to be a regression between bash-3.x and bash-4.x
Comment 4 Andrey 2011-04-14 07:39:18 UTC
(In reply to comment #3)
> seems like a simple variant of bug 310197.  simple test case:
> f() { for (( :; :; )) ; do
> cat <<EOF
> EOF
> done; :; }
> type f
> 
> seems to be a regression between bash-3.x and bash-4.x

The problem is not exactly the same but may be related.
Bug 310197 is "bash executes function incorrectly" while current bug is "bash executes function properly but dumps it improperly".

I.e., the bash script
"""
src_install () {
        for (( i = 0; i < 2; i++ )) ; do
                cat <<EOFF
${i}
EOFF
        done

        echo qqq
}

src_install
"""
works as expected but "declare -f src_install" dumps incorrect function representation.
Comment 5 SpanKY gentoo-dev 2011-04-15 08:22:35 UTC
no, they're the same bug.  even upstream said this.  read the referenced one again.  the issue only comes up when the source is dumped and reloaded.
Comment 6 Andrey 2011-04-15 13:16:20 UTC
(In reply to comment #5)
> no, they're the same bug.  even upstream said this.  read the referenced one
> again.  the issue only comes up when the source is dumped and reloaded.

Ouch, sorry, I haven't read through that thread carefully and now I see I was wrong.
Comment 7 SpanKY gentoo-dev 2011-04-15 16:14:06 UTC
not a problem.  often times upstream posts a patch quickly, but until then, you can simply work around the issue by putting a ":" after the `cat`.
Comment 8 Andrey 2011-04-15 23:42:13 UTC
(In reply to comment #7)
> not a problem.  often times upstream posts a patch quickly, but until then, you
> can simply work around the issue by putting a ":" after the `cat`.

Thank you for contacting upstream!
Yeah, thanks, I know the workaround.:)
Comment 9 SpanKY gentoo-dev 2011-04-29 22:53:52 UTC
ive added a patch from upstream to 4.2_p8-r1

http://sources.gentoo.org/app-shells/bash/files/bash-4.2-print-heredoc.patch?rev=1.1