[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: question on retrieving map(-A) value w/indirect name
From: |
Greg Wooledge |
Subject: |
Re: question on retrieving map(-A) value w/indirect name |
Date: |
Mon, 19 Mar 2018 08:56:38 -0400 |
User-agent: |
NeoMutt/20170113 (1.7.2) |
On Fri, Mar 16, 2018 at 05:50:04PM -0700, L A Walsh wrote:
> 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.
1) USE A REAL PROGRAMMING LANGUAGE.
2) Or use bash's "declare -n" (almost-like-a-nameref) syntax.
2a) Realize how bad "declare -n" actually is. How it doesn't avoid the
fundamental name conflict problem.
https://mywiki.wooledge.org/BashFAQ/048#The_problem_with_bash.27s_name_references
2b) => USE A REAL PROGRAMMING LANGUAGE.
3) Or redesign your code so that you don't need to pass an associative
array to a function by reference, since bash can't actually do that.
4) Or try that god-damned HACK that two people have posted.
4a) Realize how bad the god-damned HACK actually is. How it doesn't
avoid the fundamental name conflict problem (in addition to being
a million-monkey feces-fling that just happens to not blow up in
the current versions of bash).
4b) => USE A REAL PROGRAMMING LANGUAGE.