[Top][All Lists]

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

Re: Parsing error when "case" in "for" in $()

From: Steven W. Orr
Subject: Re: Parsing error when "case" in "for" in $()
Date: Tue, 11 Sep 2012 17:31:36 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120605 Thunderbird/13.0

On 09/11/12 17:20, quoth Chris F.A. Johnson:
On Tue, 11 Sep 2012, Benoit Vaugon wrote:
 Cannot use "case" construction in a "for" loop in a $() sub shell.
 Should work but produces parsing error.

 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 $(

 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)

Thanks. I didn't know that the opening paren was optional and was needed in such a case as a disambiguator. Very nice. And if you really want to match something that starts with an open paren, just backslash it.

As a style issue, it makes me wonder if I should always use the optional open paren as syntactic sugar...

Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net

reply via email to

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