Chet Ramey wrote:
On 3/16/18 8:50 PM, L A Walsh wrote:
I'm a bit confused ...
If I have assoc-array:
declare -A foo=([one]=11 [two]=22)
and am passing name in another var, like "fee"
fee=foo
I tried echoing the val:
echo ${!fee[one]}
but got nothing -- tried a few other syntaxes.
This has come up a number of times. Here's a message from 2002 explaining
the details:
https://lists.gnu.org/archive/html/bug-bash/2002-08/msg00119.html
I see....but that begs the question, how do you access an array's
members using a var holding the array's name?
I wanted to be able to do something like have a set of
values in an assoc. map, and pass the name to a generic
processing routine with the map name as a param, like:
sub processSrvState() {
my stat=${1:?}
if [[ ${!stat[cur_up]} == ${!stat[max_up]} &&
${!stat[cur_down]} == ${!stat[max_down]} ]]; then
...
fi
but it seems less than straight-forward. Is this possible?
I can likely think of ways around it, but none are very str8-forward
or attractive....(sigh)...
Tnx & tnx for the pointer...