|
| From: | L A Walsh |
| Subject: | Re: question on retrieving map(-A) value w/indirect name |
| Date: | Sat, 17 Mar 2018 20:28:59 -0700 |
| User-agent: | Thunderbird |
David Margerison wrote:
processSrvState() {
local cur_up="$1[cur_up]"
local max_up="$1[max_up]"
if [[ "${!cur_up}" == "${!max_up}" ]] ; then
echo ok
fi
}
declare -A foo=([cur_up]=11 [max_up]=11)
processSrvState foo
# note that the array name must not conflict with any keys
Thanks for the idea. I put it into a general sub for my use
(no error checking in this version):
hval() { # 1st=mapname, 2nd=key, 3rd=opt. outvar name
dcl _hkey="$1[$2]" nl=""
[[ ! $3 ]] && nl="\n"
printf ${3:+-v $3} "%s$nl" ${!_hkey}
}
so for:
dcl A foo=([one]=1 [two]=2) hval foo two
2
hval foo two outv echo $outv
2 Thanks much!
| [Prev in Thread] | Current Thread | [Next in Thread] |