bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

question on retrieving map(-A) value w/indirect name


From: L A Walsh
Subject: question on retrieving map(-A) value w/indirect name
Date: Fri, 16 Mar 2018 17:50:04 -0700
User-agent: Thunderbird


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.

If I ignore the indirect char '!', and do it the
old way but using eval, it works:

 eval "echo \${$fee[one]}"
 11

Question -- why did '!' replace the 2nd $ if it doesn't
work in arrays?

echo ${$fee[one]} seems like a more natural syntax (besides
the fact that modern bash seems to be unable to parse it).

Was there a reason for going with '!' instead of $?
like the ${!fee} for simple, non-array case replacing $$fee?

If we went to the trouble of converting to '!' why doesn't
it work with newer data structures like arrays?

Aw..shucks...um seems like ${!NAME is overloaded?  How do
they relate? Or why same type of syntax for accessing
keynames instead of values for ARRAYS but used for indirection for
simple vars?  I don't see why the same symbol '!' was
used for both.  Are they somehow related?...

Anyway, the fact that indirection needs eval seems icky.

(yeah, I could use "-n", but less portable)

thnx
-l





reply via email to

[Prev in Thread] Current Thread [Next in Thread]