bug-bash
[Top][All Lists]
Advanced

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

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


From: Eric Blake
Subject: Re: Parsing error when "case" in "for" in $()
Date: Tue, 11 Sep 2012 16:30:10 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120828 Thunderbird/15.0

On 09/11/2012 03:31 PM, Steven W. Orr wrote:
>>> 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)
>>
> 
> 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...

POSIX has always required an optional open paren to case patterns,
thanks to ksh; but it hasn't been portable to all shells until recently
(among others, Solaris /bin/sh will fail if you try it, but then again,
that's not a POSIX shell).

-- 
Eric Blake   eblake@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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