Ordered associative arrays in bash
I can do the following in bash: declare -A data data[A]="aaa" data[C]="ccc" data[B]="bbb" for i in "${!data[@]}" ; do printf "%-20s ---> %s\n" "$i" "${data[$i]}" done Which outputs: A ---> aaa B ---> bbb C ---> ccc That is, the associative array is reordered (I assume using lexicographic ordering on the keys, but I am not sure), and loses the original order in which I created the data. I wanted instead: A ---> aaa C ---> ccc B ---> bbb In python I would use an OrderedDict instead of a plain dict for that. Is there a similar concept in bash?
0 upvotes
View original discussion ↗
Comments
Sign in or sign up to comment and upvote.
No comments yet.