Earlier quoted context omitted.
You should be getting bash from homebrew anyways.
Just use the included zsh.
Today I learned that bash has hashmaps (2024)
41–50 of 137 posts
Re: Today I learned that bash has hashmaps (2024)
#42For example: `${!myvar[@]}` would list all of the keys.
I've written about associative arrays in Bash a bit here: https://nickjanetakis.com/blog/associative-arrays-in-bash-ak...
Re: Today I learned that bash has hashmaps (2024)
#43Earlier quoted context omitted.
You should probably read the release notes for new major versions. Also, anytime you think “ I wish there was available in this program ”, you should probably double-check if such a feature has appeared since you last learned the program.
That's how I discovered the '&' regex feature in less some years back.
Re: Today I learned that bash has hashmaps (2024)
#44IIRC, the latest bash addresses all of these, but that doesn't help too much if you are stuck with an older, stable OS, e.g., RHEL 7 or 8; even 9 likely has a few remaining.
These leaks become an issue if you have a long running bash script with frequent adds and updates. The update leak can be mitigated somewhat by calling unset, e.g., unset a[b], before updating, but only partially (again, apologies, no notes, just the memory of the discovery and the need to drop bash).
I'd agree with the idea that bash wasn't the best choice for this purpose in the first place, but there was history and other technical debt involved.
Re: Today I learned that bash has hashmaps (2024)
#45Re: Today I learned that bash has hashmaps (2024)
#46It’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…
Totally agree with that - I maintain a big txt file too.
Maybe this bash compendium is a bit similar:
Re: Today I learned that bash has hashmaps (2024)
#47It’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…
• https://learnxinyminutes.com/>
And some code search engines:
• Debian: https://codesearch.debian.net/>
• Python: https://www.programcreek.com/python/>
• Linux: https://livegrep.com/search/linux>
• GitHub: https://grep.app/>
• HTML, JS and CSS: https://publicwww.com/>
Re: Today I learned that bash has hashmaps (2024)
#48Not 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)
#49Picky and probably pointless question: are they actually hashmaps? If I understand correctly, a hashmap isn’t the only way to implement an associative array.
Seems to suggest it's indeed a hashmap in implementation, but I can't be bothered to look any closer.
Re: Today I learned that bash has hashmaps (2024)
#50Earlier quoted context omitted.
That's how I discovered the '&' regex feature in less some years back.
Do you mean PCRE’s “(?&name)” feature? That is not portable; for instance, Python calls it “(?P=name)”. Or do you mean the common feature of “&” in the replacement string meaning “the whole matched string”? While this feature is common in languages which use regexps (including ed, sed, awk, etc.), that’s not actually a regexp feature, since the & character has that effect in the replacement string , not in the regula…
&pattern
Display only lines which match the pattern; lines which do not
match the pattern are not displayed. If pattern is empty (if
you type & immediately followed by ENTER), any filtering is
turned off, and all lines are displayed. While filtering is in
effect, an ampersand is displayed at the beginning of the
prompt, as a reminder that some lines in the file may be hidden.
$ less --version
less 487 (GNU regular expressions)
Copyright (C) 1984-2016 Mark Nudelman