Showing posts with label associative array. Show all posts
Showing posts with label associative array. Show all posts

Tuesday, December 15, 2009

bash version 4 and associative arrays

The new builtin array variable BASH_ALIASES is a nice example for an associative array.
If you do an ''echo ${BASH_ALIASES[@]}" you see all the values, if you do a "set | fgrep BASH_ALIASES" you see, to what the indexes map.

Update:

In December, when I got aware of the new feature, I thought, there is no way to get the list of indexes.
But there is:  ${!name[@]} and ${!name[*]} return the list of array keys. This gets explained in the section Parameter Expansion. I am sorry, if my former statements caused confusion.


Monday, November 23, 2009

using associative arrays in your code

How many lines of code does it take for your new piece of code, before you introduce an associative array?


How many lines of code does it take for your new piece of code, before you introduce a class?

Yes, I know, Bourne shell doesn't come with the concept of associative arrays, of course it also doesn't know classes or object orientation. Right, a simple 20 or 30 lines shell script for copying and renaming files may not have the need for associative arrays or classes. But if your script gets longer, pls rethink, whether Bourne shell is the right choice for your task, or whether you make really good use of ruby, perl, or python!

Your next steps may be writing unit testing and using continuous integration. It's not your customer, who should request it, it should be your serious professional style, your way to deliver proper services. If you are not familiar with the terms, look them up -- I provided you with proper links to interesting and informative articles.