What is the equivalent of Python dictionaries but in Bash (should work across OS X and Linux).
相关问题
- JQ: Select when attribute value exists in a bash a
- Move character on map on clicked position
- bash print whole line after splitting line with if
- “command not found” errors in expect script execut
- grep using grep results
相关文章
- Check if directory exists on remote machine with s
- Reverse four length of letters with sed in unix
- Creating a dictionary for each word in a file and
- Launch interactive SSH bash session from PHP
- BASH: Basic if then and variable assignment
- Bash script that creates a directory structure
- Test if File/Dir exists over SSH/Sudo in Python/Ba
- Can a VBScript function return a dictionary?
I really liked Al P's answer but wanted uniqueness enforced cheaply so I took it one step further - use a directory. There are some obvious limitations (directory file limits, invalid file names) but it should work for most cases.
It also performs a tad bit better in my tests.
Just thought I'd pitch in. Cheers!
Edit: Adding hdestroy()
Prior to bash 4 there is no good way to use associative arrays in bash. Your best bet is to use an interpreted language that actually has support for such things, like awk. On the other hand, bash 4 does support them.
As for less good ways in bash 3, here is a reference than might help: http://mywiki.wooledge.org/BashFAQ/006
There's parameter substitution, though it may be un-PC as well ...like indirection.
The BASH 4 way is better of course, but if you need a hack ...only a hack will do. You could search the array/hash with similar techniques.