[Top][All Lists]

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

[Help-bash] Order of element in associative array expansion

From: Davide Brini
Subject: [Help-bash] Order of element in associative array expansion
Date: Thu, 17 Oct 2013 18:23:27 +0200

I know that the order of keys and values obtained by expanding an
associative array with "address@hidden" and "address@hidden" respectively is
unpredictable, which is fine.

However my question is: at a given point in time, without changes or other
operations happening in between, are the two expansions guaranteed to
return the keys in the same order as the respective values and viceversa?

In other words:

$ declare -p a
declare -A a='([k3]="v3" [k2]="v2" [k1]="v1" )'
$ echo "address@hidden"
k3 k2 k1
$ echo "address@hidden"
v3 v2 v1

When "address@hidden" expands to "k3" "k2" "k1" as above, could 
"address@hidden" expand
to an order that is not "v3" "v2" "v1"? My tests seems to confirm that the
two orderings are always consistent, but I havent't found documentation to
confirm (or negate) this. If the answer is "you can't rely on that" that's
fine. (Note again I'm NOT asking that the order of the expansion be
predictable, only that the two expansions for the keys and the values have
a consistent ordering, whatever it may be)


reply via email to

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