bug-bash
[Top][All Lists]
Advanced

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

Re: Shell case statements


From: Chet Ramey
Subject: Re: Shell case statements
Date: Fri, 20 May 2011 11:33:42 -0400
User-agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10

On 5/19/11 6:09 PM, Eric Blake wrote:
> [adding bug-bash]
> 
> On 05/16/2011 07:23 PM, Wayne Pollock wrote:
>> (While cleaning up the standard for case statement, consider that it is 
>> currently
>> unspecified what should happen if an error occurs during the expansion of the
>> patterns; as expansions may have side-effects, when an error occurs on one
>> expansion, should the following patterns be expanded anyway?  Does it depend 
>> on
>> the error?  It seems reasonable to me that any errors should immediately 
>> terminate
>> the case statement.)
> 
> Well, that's rather all over the place, but yes, it does seem like bash
> was the buggiest of the lot, compared to other shells.  Interactively, I
> tested:
> 
> readonly x=1
> case 1 in $((x++)) ) echo hi1 ;; *) echo hi2; esac
> echo $x.$?
> 
> bash 4.1 printed:
> bash: x: readonly variable
> hi1
> 1.0
> which means it matched '1' to $((x++)) before reporting the failure
> assign to x, and the case statement succeeded.  Changing the first "1"
> to any other string printed hi2  (the * case).

Thanks for the report.  This was an easy fix.  The variable assignment
error was actually handled correctly, the expression evaluation code
just didn't pay enough attention to the result.

Chet
-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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