Live data from Hacker News

Today I learned that bash has hashmaps (2024)

xeiaso.net

31–40 of 137 posts

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

#31
post #13

It’s amazing how much of a superpower merely reading the manual is nowadays. https://www.gnu.org/software/bash/manual/bash.html#Arrays >

My one-shot memory worsened with years but grasping concepts from examples got much better due to experience. So I find walls of text much less useful than a continuous “synopsis” of snippets and best practices. One usage example is worth a hundred of words and few pages of it may be worth a whole manual, especially when “at hand” through editor means. For bash idk if that exists on the internet, so I maintain my own in my one big text file. I wish every manual had the synopsis-only section (maybe I should just LLM these).

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

#32
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.

You should be getting bash from homebrew anyways.

Or using an OS which doesn’t ship ancient software. Linux exists. It’s pretty awesome.

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

#33
post #19

Picky 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)

#35
post #27

To 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.

Isn't this basically the same feature that existed in ksh93?

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

#36
post #32

Earlier quoted context omitted.

You should be getting bash from homebrew anyways.

Or using an OS which doesn’t ship ancient software. Linux exists. It’s pretty awesome.

Only until you find that your requirement or use case doesn’t work in it.

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

#37
I discover stuff like this every day, and it’s delightful. Sure, reading the manual would’ve saved me from the surprise, but it’s incredibly difficult for me to read them unless I have a specific goal in hand.

I 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.

[1]: https://rednafi.com/misc/associative_arrays_in_bash/

[2]: https://rednafi.com/misc/dynamic_shell_variables/

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

#38
post #33
post #19

Picky 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.

I think many devs don't know the difference and simply call any dictionary/associative array a hash map. It might be one of the concepts that "the internet" promotes: it sounds fancy, more technical, makes you seem more knowledgeable, so it gets repeated. Then newcomers think this is the way it's always been called, and that gives it enough visibility to become the preferred name.

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

#39
post #32

Earlier quoted context omitted.

You should be getting bash from homebrew anyways.

Or using an OS which doesn’t ship ancient software. Linux exists. It’s pretty awesome.

There's a time and place for evangelism. This isn't it.
Post reply on HN