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: Chet Ramey
Subject: Re: Minor bug declaring arrays of integers: dcl -ai=>broken, dcl -ia=>ok
Date: Sun, 21 Jul 2013 16:13:31 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:17.0) Gecko/20130328 Thunderbird/17.0.5

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 "${foo[@]}"
> 1 2 xx 3   <---------incorrect
> 
> So then tried:
> 
> 
>> declare -ia -g foo=(1 2 xx 3)  echo "${foo[@]}"
>> 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
-- 
``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]