[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Parsing error when "case" in "for" in $()
From: |
Chris F.A. Johnson |
Subject: |
Re: Parsing error when "case" in "for" in $() |
Date: |
Tue, 11 Sep 2012 17:20:50 -0400 (EDT) |
User-agent: |
Alpine 2.00 (LMD 1167 2008-08-23) |
On Tue, 11 Sep 2012, Benoit Vaugon wrote:
...
Description:
Cannot use "case" construction in a "for" loop in a $() sub shell.
Should work but produces parsing error.
Repeat-By:
echo $(for x in whatever; do case y in *) echo 42;; esac; done)
The closing parentheses in the case statement is being interpreted as the
closing for $(
Fix:
Probably by fixing the bash parser.
Balance the parentheses in the case statement:
echo $(for x in whatever; do case y in (*) echo 42;; esac; done)
--
Chris F.A. Johnson, <http://cfajohnson.com/>
Author:
Pro Bash Programming: Scripting the GNU/Linux Shell (2009, Apress)
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)