bug-bash
[Top][All Lists]
Advanced

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

Re: Minor bug declaring arrays of integers: dcl -ai=>broken, dcl -ia=>ok


From: Dan Douglas
Subject: Re: Minor bug declaring arrays of integers: dcl -ai=>broken, dcl -ia=>ok
Date: Sun, 21 Jul 2013 21:35:54 -0500
User-agent: KMail/4.10.5 (Linux/3.10.1-pf+; KDE/4.10.5; x86_64; ; )

On Sunday, July 21, 2013 04:13:31 PM Chet Ramey wrote:
> On 7/14/13 5:03 PM, Linda Walsh wrote:
> > In order to declare an array of type int (or an integer array)
> > I first tried:
> > 
> >> declare -ai -g foo=(1 2 xx 3)
> >> echo "address@hidden"
> > 1 2 xx 3   <---------incorrect
> > 
> > So then tried:
> > 
> > 
> >> declare -ia -g foo=(1 2 xx 3)  echo "address@hidden"
> >> 1 2 0 3  <---------correct!
> > 
> > It seems 'declare' is sensitive to the order of its options in an
> > undesirable way -- i.e. for typed arrays, the -i should be
> > allowed either before or after the -a (or -A for hashes).
> > 
> > That makes me wonder if the "-g" worked.
> > I.e. -- if "-g" after "-ia" works, and whether I need "-g -ia"
> > (or "-gia")
> 
> Thanks for the report.  This will be fixed in bash-4.3.  You can work
> around it until bash-4.3 is released by splitting the attribute and
> value assignments:
> 
> declare -ai -g foo
> foo=(1 2 xx 3)
> 
> (For what it's worth, I don't see a difference in the output no matter what
> the option order.)
> 
> Chet

What's the bug? I can't reproduce this and always get "xx" no mater the option 
order.

I always assumed the -i attribute doesn't get set until after assigning the 
values, which is why:

     $ ( declare -ia foo=(1 2 xx 3); echo "address@hidden" )
    1 2 xx 3

always gives you the xx, while forcing the evaluation to be done within 
declare's environment gives a different result (e.g. with quotes):

     $ ( declare -ia 'foo=(1 2 xx 3)'; echo "address@hidden" )
    1 2 0 3

I think this was already known and not a bug, and doesn't have to do with the 
order options are supplied in.

-- 
Dan Douglas



reply via email to

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