Hello!

 I firmly believe that the attached patch fixes the problem at hand; what
it breaks I have no idea. Kindly requesting a review.

cheers,
pg

P.S.
 it also fixes others of the similar type, e.g.:

x=$(case 1 in 1) echo 1;; esac; case 2 in 2) echo 2;; esac;)
echo $x

P.P.S.
 vim :syntax notices the original parsing error, probably assuming ')' in
case value closes command subsitution. That, however, is beyond my ability
to fix.


On Tue, Mar 29, 2016 at 7:43 PM, Christian Franke <
christian.fra...@t-online.de> wrote:

> Configuration Information [Automatically generated, do not change]:
> Machine: i686
> OS: cygwin
> Compiler: gcc
> Compilation CFLAGS:  -DPROGRAM='bash.exe' -DCONF_HOSTTYPE='i686'
> -DCONF_OSTYPE='cygwin' -DCONF_MACHTYPE='i686-pc-cygwin' -DCONF_VENDOR='pc'
> -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H
> -DRECYCLES_PIDS   -I. -I/usr/src/bash-4.3.42-4.i686/src/bash-4.3
> -I/usr/src/bash-4.3.42-4.i686/src/bash-4.3/include
> -I/usr/src/bash-4.3.42-4.i686/src/bash-4.3/lib  -DWORDEXP_OPTION -ggdb -O2
> -pipe -Wimplicit-function-declaration
> -fdebug-prefix-map=/usr/src/bash-4.3.42-4.i686/build=/usr/src/debug/bash-4.3.42-4
> -fdebug-prefix-map=/usr/src/bash-4.3.42-4.i686/src/bash-4.3=/usr/src/debug/bash-4.3.42-4
> uname output: CYGWIN_NT-6.1-WOW Alien2 2.4.1(0.293/5/3) 2016-01-24 11:24
> i686 Cygwin
> Machine Type: i686-pc-cygwin
>
> Bash Version: 4.3
> Patch Level: 42
> Release Status: release
>
> Description:
> If consecutive case statements are inside of $(...), the parser
> misinterprets first ')' from second case statement as the end of command
> substitution.
>
> The possibly related patch bash43-042 is already included in this version.
>
>
> Repeat-By:
>
> $ cat bug.sh
> x=$(
>   case 1 in
>     1) echo 1
>   esac
>   case 2 in
>     2) echo 2
>   esac
> )
> echo "$x"
>
>
> $ bash -xv bug.sh
> x=$(
>   case 1 in
>     1) echo 1
>   esac
>   case 2 in
>     2) echo 2
> bug.sh: command substitution: line 13: syntax error: unexpected end of file
> bug.sh: line 7: syntax error near unexpected token `esac'
> bug.sh: line 7: ` esac'
>
>
> $ dash bug.sh
> 1
> 2
>
>
> Workarounds:
> - append semicolon behind first 'esac', or
> - insert any command line between the case statements, or
> - use `...` instead of $(...)
>
>
> --
> Christian Franke
>
>
>

Attachment: fix-case-inside-command-substitution.patch
Description: Binary data

Reply via email to