Live data from Hacker News

Today I learned that bash has hashmaps (2024)

xeiaso.net

1–10 of 137 posts

Re: Today I learned that bash has hashmaps (2024)

#5
post #4

A couple of weeks ago I learnt that Bash on Mac does not have associative arrays. We worked around the issue by changing the script to run under Zsh, but beware.

Sounds like a bash 3 issue.

$ bash --version

GNU bash, version 5.2.32(1)-release (aarch64-apple-darwin23.4.0)

$ declare -A aaa; aaa[a]=a; aaa[b]=bb; for i in ${!aaa[@]}; do echo "$i --> ${aaa[$i]}"; done

b --> bb

a --> a

Re: Today I learned that bash has hashmaps (2024)

#10
post #5
post #4

A couple of weeks ago I learnt that Bash on Mac does not have associative arrays. We worked around the issue by changing the script to run under Zsh, but beware.

Sounds like a bash 3 issue. $ bash --version GNU bash, version 5.2.32(1)-release (aarch64-apple-darwin23.4.0) $ declare -A aaa; aaa[a]=a; aaa[b]=bb; for i in ${!aaa[@]}; do echo "$i --> ${aaa[$i]}"; done b --> bb a --> a

To elaborate on this, macOS default bash is still stuck (assuming due to licensing) in v3.2.x (released in 2007). Bash got associative arrays in v4 (released in 2009).
Post reply on HN