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 c...@case.edu http://cnswww.cns.cwru.edu/~chet/