bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

$() does not handle nesting with case - parser precedence?


From: Nathan Neulinger
Subject: $() does not handle nesting with case - parser precedence?
Date: Sat, 27 Jun 2015 14:48:02 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0

Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-redhat-linux-gnu' -DCONF_VENDOR='redhat' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include -I./lib -D_GNU_SOURCE -DRECYCLES_PIDS -DDEFAULT_PATH_VALUE='/usr/local/bin:/usr/bin' -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic uname output: Linux skyhawk.home.neulinger.org 3.19.3-200.fc21.x86_64 #1 SMP Thu Mar 26 21:39:42 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-redhat-linux-gnu

Bash Version: 4.3
Patch Level: 39
Release Status: release

Description:

        If $() includes a case statement nested within it, the parser is not 
matching ) as closing the case,
        but rather the $(. This behavior is different between bash and other 
shells. ksh/busybox
        both process this without error, but I do not know which is officially 
"correct".

        Test Case:
---------------
testing=$(
    echo test | while read line; do
        case $line in
             test)  echo saw test ;;
             *)     echo other ;;
        esac
    done
)

echo result: $testing
--------------

        Expected output:

result: saw test

        Actual output:

parse-bug.sh: line 6: syntax error near unexpected token `;;'
parse-bug.sh: line 6: `         test)  echo saw test ;;'


        Workaround:  Use (test) instead of test) in the nested code


Repeat-By:
        Run script with that syntax.



--
------------------------------------------------------------
Nathan Neulinger                       nneul@neulinger.org
Neulinger Consulting                   (573) 612-1412



reply via email to

[Prev in Thread] Current Thread [Next in Thread]