[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] How to keep associative array order
From: |
Greg Wooledge |
Subject: |
Re: [Help-bash] How to keep associative array order |
Date: |
Tue, 30 Apr 2019 11:53:27 -0400 |
User-agent: |
Mutt/1.10.1 (2018-07-13) |
On Tue, Apr 30, 2019 at 11:35:00AM -0400, Jerry wrote:
> I want to keep an index of an associative array. I found a few methods
> on this site:
> https://stackoverflow.com/questions/29161323/how-to-keep-associative-array-order
You can keep a second array, indexed instead of associative, and use
that as the list of indices into the associative array.
choices=(a b c d e)
declare -A choicelabel=(
[a]="Alan" [b]="Betty" [c]="Charlie" [d]="Doug" [e]="Ethel"
)
for i in "address@hidden"; do
printf '%s: %s\n' "$i" "${choicelabel[$i]}"
done