On 17 March 2018 at 20:40, L A Walsh <b...@tlinx.org> wrote: > > 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
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