It’s amazing how much of a superpower merely reading the manual is nowadays.
13 comments
It’s amazing how much of a superpower merely reading the manual is nowadays.
Not only do they exist, but they have some fantastic foot guns! https://mywiki.wooledge.org/BashPitfalls#A.5B.5B_-v_hash.5B....
>they have some fantastic foot guns!
Otherwise wouldn't be getting the full shell experience.
Interesting, definitely need to keep that in mind.
> Q: How do I declare a Hashmap?
> A: You use the command `declare -A HASHMAP_NAME`
This is why I think Bash is a horrible language
Because of the -A instead of an -H? -A is for "Associative array".
what do you mean?
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.
Many programs on macOS are stuck in the ancient past, due to Apple:
<https://web.archive.org/web/20240810094701/https://meta.ath0...>
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).
You should be getting bash from homebrew anyways.
Just use the included zsh.