|
|
|
|
|
by syntacticbs
520 days ago
|
|
Oh dear. I've been trying to get people to not use this feature for a while. One thing that has bitten me in the past is that, if you declare your associative arrays within a function, that associative array is ALWAYS global.
Even if you declare it with `local -A` it will still be global.
Despite that, you cannot pass an associative array to a function by value. I say "by value" because while you can't call `foo ${associative_array}` and pick it up in foo with `local arg=$1, you can pass it "by reference" with `foo associative_array` and pick it up in foo with `local -n arg=$1`, but if you give the passed in dereferenced variable a name that is already used in the global scope, it will blow up, eg `local -n associative_array=$1`. As a general rule for myself when writing bash, if I think one of my colleagues who has an passable knowledge of bash will need to get man pages out to figure out what my code is doing, the bash foo is too strong and it needs to be dumbed down or re-written in another language. Associative arrays almost always hit this bar. |
|