Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

`declare -fp` mishandles heredoc with || statement

2 views
Skip to first unread message

Mike Frysinger

unread,
May 31, 2013, 10:37:17 PM5/31/13
to bug-...@gnu.org
simple code snippet:
$ cat test.sh
func() {
cat > / <<EOF || echo FAIL
11
EOF
}
declare -fp

when run, we see the || statement is incorrectly moved to after the heredoc:
$ bash ./test.sh
func ()
{
cat > / <<EOF
11
EOF
|| echo FAIL
}

every version of bash i tried fails this way (2.05b through 4.2.45)
-mike
signature.asc

Chris F.A. Johnson

unread,
May 31, 2013, 11:27:06 PM5/31/13
to Mike Frysinger, bug-...@gnu.org
With 4.2.37:

func ()
{
cat > / <<EOF ||
11
EOF
echo FAIL
}

--
Chris F.A. Johnson, <http://cfajohnson.com/>
Author:
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)

Chet Ramey

unread,
Jun 1, 2013, 5:07:33 PM6/1/13
to Mike Frysinger, bug-...@gnu.org, chet....@case.edu
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 5/31/13 10:37 PM, Mike Frysinger wrote:
> simple code snippet:
> $ cat test.sh
> func() {
> cat > / <<EOF || echo FAIL
> 11
> EOF
> }
> declare -fp
>
> when run, we see the || statement is incorrectly moved to after the heredoc:
> $ bash ./test.sh
> func ()
> {
> cat > / <<EOF
> 11
> EOF
> || echo FAIL
> }
>
> every version of bash i tried fails this way (2.05b through 4.2.45)

I don't get this. I see, when using bash-4.2.45:

$ ./bash-4.2-patched/bash ./x1
func ()
{
cat > /tmp/xxx <<EOF ||
11
EOF
echo FAIL
}

I get the same thing going all the way back to bash-4.0. I see the same
results you do on bash-3.2.51, but that's old enough that it's not going
to change.

Chet
- --
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU ch...@case.edu http://cnswww.cns.cwru.edu/~chet/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlGqYo4ACgkQu1hp8GTqdKvGJgCfbyxPaZCd4yQOthCXdWwxGqHC
I34An14UuDqYYcKE9ONVH+8SPj9FCJ2U
=W3hu
-----END PGP SIGNATURE-----

Mike Frysinger

unread,
Jun 1, 2013, 10:08:54 PM6/1/13
to chet....@case.edu, bug-...@gnu.org
err, yeah, sorry. running too many versions of bash (like 10) made me miss
the subtle nuance of the || being up top vs down below. bash-4.0+ work.
-mike
signature.asc
0 new messages