It’s amazing how much of a superpower merely reading the manual is nowadays. https://www.gnu.org/software/bash/manual/bash.html#Arrays >
Today I learned that bash has hashmaps (2024)
31–40 of 137 posts
Re: Today I learned that bash has hashmaps (2024)
#32A 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.
You should be getting bash from homebrew anyways.
Re: Today I learned that bash has hashmaps (2024)
#33Picky and probably pointless question: are they actually hashmaps? If I understand correctly, a hashmap isn’t the only way to implement an associative array.
Re: Today I learned that bash has hashmaps (2024)
#34Not only do they exist, but they have some fantastic foot guns! https://mywiki.wooledge.org/BashPitfalls#A.5B.5B_-v_hash.5B....
Re: Today I learned that bash has hashmaps (2024)
#35To me, this is a development in the wrong direction. Shell is great precisely because it's so minimal. Everything is string rule is one that calms all of your type-induced fears. Having to implement hash-tables, while still keeping the appearances of everything being a string is the anti-pattern known as "string programming" (i.e. when application develops a convention about storing type / structure information insid…
> To me, this is a development in the wrong direction. That ship has sailed. These were introduced in Bash 4, released in 2009, and Bash is already on version 5.
Re: Today I learned that bash has hashmaps (2024)
#36Re: Today I learned that bash has hashmaps (2024)
#37I found out about hashmaps in Bash a year ago[1], and it came as a surprise. This morning, I came across dynamic shell variables and the indirection syntax[2]. Each time I wrote about them and learned more than I would have if I had just passively grokked the manual.
Re: Today I learned that bash has hashmaps (2024)
#38Picky and probably pointless question: are they actually hashmaps? If I understand correctly, a hashmap isn’t the only way to implement an associative array.
That is certainly true - associative arrays in c++ (std::map) for example, are implemented as red-black trees.
Re: Today I learned that bash has hashmaps (2024)
#39Re: Today I learned that bash has hashmaps (2024)
#40[0]: https://hyperpolyglot.org/unix-shells#associative-arrays