Bug 1241023

Summary: case in a for loop inside subshell causes syntax error
Product: Red Hat Enterprise Linux 7 Reporter: Martin Kyral <mkyral>
Component: zshAssignee: Kamil Dudka <kdudka>
Status: CLOSED ERRATA QA Contact: Jan Kepler <jkejda>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.1CC: hannsj_uhl, isenfeld, jkejda, msvistun, ovasik, qe-baseos-apps
Target Milestone: rcKeywords: Patch
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: zsh-5.0.2-13.el7 Doc Type: Bug Fix
Doc Text:
Previously, zsh did not correctly parse command substitutions. As a consequence, zsh in some cases reported syntax errors for syntactically valid shell scripts. With this update, the parser has been fixed to parse shell scripts correctly.
Story Points: ---
Clone Of: 1212775 Environment:
Last Closed: 2015-11-19 05:20:40 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Martin Kyral 2015-07-08 10:15:59 UTC
zsh in RHEL 7 has the same issue. Additionally, this code:
x=$(case $i in test) echo test;; esac) which works in bash, doesn't work in zsh

Version-Release number of selected component (if applicable):
zsh-5.0.2-7.el7

+++ This bug was initially created as a clone of Bug #1212775 +++

Description of problem:

# this works
$ x=$(for i in test; do echo $i; done)
$ echo $x
test

# this too, works
$ i=test
$ x=$(case $i in test) echo test;; esac)
$ echo $x
test

# this does not
$ x=$(for i in test; do case $i in test) echo test;; esac; done)
-bash: syntax error near unexpected token `;;'

# however removing the output-into-variable makes it work
$ (for i in test; do case $i in test) echo test;; esac; done)
test


Version-Release number of selected component (if applicable):
bash-4.2.46-12.el7

How reproducible:
always

Actual results:
expression fails on syntax error

Expected results:
the subshell output is assigned to a variable

Additional info:
This *works* on my bash-4.3.30-2.fc21, so there might have been an upstream fix.

--- Additional comment from Ondrej Oprala on 2015-04-18 09:36:45 EDT ---

Hi Jiri,
Yes, this was fixed in 4.3. I have yet to look at the size of the change.

Meanwhile, the more verbose way of writing a case statement still seems to work:
x=$(for i in test; do case $i in (test) echo test;; esac; done)
#                                ^^

Comment 2 Kamil Dudka 2015-07-08 12:02:57 UTC
upstream commit:

http://sourceforge.net/p/zsh/code/ci/c0d01a6f

Comment 6 Kamil Dudka 2015-07-28 08:42:45 UTC
The upstream fix causes a serious regression:

http://www.zsh.org/mla/workers/2015/msg01855.html
http://www.zsh.org/mla/workers/2015/msg01856.html

As of yet, there is no upstream fix available.  Unless we get one, we will have to revert the patch for this bug and defer the solution to a future update of RHEL-7.

@QE: Could you please include the above test-cases in our test plans?

Comment 8 Kamil Dudka 2015-07-30 14:47:47 UTC
(In reply to Kamil Dudka from comment #6)
> The upstream fix causes a serious regression:
> 
> http://www.zsh.org/mla/workers/2015/msg01855.html
> http://www.zsh.org/mla/workers/2015/msg01856.html

Now fixed by upstream commits:

http://sourceforge.net/p/zsh/code/ci/2ef4b384
http://sourceforge.net/p/zsh/code/ci/c0a80171

Comment 13 errata-xmlrpc 2015-11-19 05:20:40 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2015-2208.html