|
From: | Dennis Williamson |
Subject: | Re: $() does not handle nesting with case - parser precedence? |
Date: | Sun, 28 Jun 2015 14:57:59 -0500 |
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
[Prev in Thread] | Current Thread | [Next in Thread] |