0

I have the following hashmap code in bash-

declare -A PUBS

PUBS=( "FEE":"[345, 342]" "FOO":"[1, 2, 44]" "BAR":"[23, 67]" )

for pub in "${PUBS[@]}"
do
    PUB_DOMAIN="$pub"
    CAT="${PUBS[$pub]}"
    printf "Key is %s" "$PUB_DOMAIN"
    printf "\n"
done

The $PUB_DOMAIN here prints the values- [345, 342], instead of keys.

What's wrong here?

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
kev
  • 2,741
  • 5
  • 22
  • 48
  • @Socowi I wrote the above code in reference to that, couldn't figure out why it's always printing values instead of keys. – kev Mar 12 '19 at 22:15
  • It's expected that you'll list your references when asking the question, when discussing what you tried already. If there's a duplicate that gives the exact answer you need, the reasonable expectation is that you haven't seen it yet -- but even when that's not the case, as here, being linked back to it *did* apparently lead to you finding your problem. – Charles Duffy Mar 12 '19 at 22:25
  • BTW, answers don't belong in questions, including closed ones. See [What should I do when the answer of a (closed) question is added to the question itself?](https://meta.stackoverflow.com/questions/377643/what-should-i-do-when-the-answer-of-a-closed-question-is-added-to-the-question) on [meta]. – Charles Duffy Mar 12 '19 at 22:27

0 Answers0