[buug] bash bug (bug also apparently in, and not in, some other shells)

Michael Paoli Michael.Paoli at cal.berkeley.edu
Sat Aug 6 08:32:26 PDT 2011


> From: "Ian Zimmerman" <itz at buug.org>
> Subject: Re: [buug] loops and pipe sinks are subshells, aaaargh
> Date: Sat, 06 Aug 2011 02:38:31 -0700

> Did you report the bash bug?  Sounds scary.

I don't know about "scary", but stupid and annoying bug.

Looks like it's known bug, and also apparently known upstream (GNU):
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=86397
Looks the bug is also present in some non-bash shells, but not in some others.
There's also apparently some alternate case syntax that can be used as
work-around.

Current stable Debian uses dash for /bin/sh :-) and dash
doesn't have that bug.

I was gathering information to report it, but looks like that would've
been quite redundant, as it's apparently already known, reported, and
currently open bug (though unfortunately doesn't sound likely to be
fixed anytime soon).  Some of what I'd put together:

Subject: fails to parse pattern in case in loop in $()

Description:
fails to parse pattern in case in loop in $() command substitution

Repeat-By:
rather minimalist example demonstrations found thus far:
$ expand -t 4 bug
#!/bin/sh

if [ x"${BASH_VERSION+bash}" = xbash ]; then
     set -o posix
     echo $BASH_VERSION
fi

$(
     for x in x; do
         case "$x" in
             x)
                 :
             ;;
         esac
     done
)
$ expand -t 4 bug2
#!/bin/sh

if [ x"${BASH_VERSION+bash}" = xbash ]; then
     set -o posix
     echo $BASH_VERSION
fi

$(
     < /dev/null while read x; do
         case "$x" in
             x)
                 :
             ;;
         esac
     done
)
Example runs:
$ ./bash-4.2/bash bug
4.2.0(1)-release
bug: command substitution: line 16: syntax error: unexpected end of file
bug: line 13: syntax error near unexpected token `;;'
bug: line 13: `                 ;;'
$ ./bash-4.2/bash bug2
4.2.0(1)-release
bug2: command substitution: line 13: syntax error near unexpected token `do'
bug2: command substitution: line 13: `  < /dev/null while read x; do'
bug2: line 13: syntax error near unexpected token `;;'
bug2: line 13: `                        ;;'
$
problem occurs under at least these bash versions:
4.2.0(1)-release
3.00.15(1)-release
2.05b.0(1)-release
problem does not occur under dash or ash shells.
problem does not occur:
if `` command substitution syntax is used instead of $()
if the while or for loop (but not its contents) is removed
if the case statement contains no pattern section(s)

Fix:
inelegant workarounds: use `` instead of $(), or dash or ash or
other POSIX/SUS compliant shells instead of bash




More information about the buug mailing list