[Top][All Lists]

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

Re: declare a="$b" if $a previously set as array

From: Chet Ramey
Subject: Re: declare a="$b" if $a previously set as array
Date: Mon, 22 Dec 2014 20:15:35 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:31.0) Gecko/20100101 Thunderbird/31.2.0

On 12/16/14 2:53 AM, Dan Douglas wrote:
> On Sunday, December 14, 2014 02:39:29 PM Chet Ramey wrote:
>> And we get to the fundamental issue.  Is it appropriate to require
>> arguments to declaration commands to be valid assignment statements when
>> the parser sees them, instead of when the builtin sees them, at least
>> when using the compound assignment syntax.
>> I'm ok with tightening the rules and saying that it is, but it's not
>> backwards compatible and changes the behavior of things like
>> declare -a foo='(1 2 3)'
>> which I imagine plenty of people have used and has been a supported way
>> to do compound assignment for many years.
> That would be one way but I think this can be solved without going quite
> so far. How do you feel about these rules?
>       1. If a word that is an argument to declare is parsed as a valid
>          assignment, then perform the assignment immediately as it appears
>          lexically. If such a word is parsed as a simple assignment (with or
>          without an index) then bash treats it as a simple scalar assignment 
> to
>          the variable or array element as any ordinary assignment would. If 
> word
>          is parsed as an assignment with array initializer list then bash 
> treats
>          it as such.

This doesn't quite work, since there are assignments that affect how the
value is treated.  For instance,

declare -a -i foo=(1+1 2+2 3+3)

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

reply via email to

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