title: Multidimensional associative arrays in Bash
body: <p>I'm trying to create a multidimensional associative array but need some help. I have reviewed <a href="https://stackoverflow.com/questions/3020713/how-to-print-bash-varibles-contents-into-two-dimensional-array-bash-shell">the page suggested in this SO answer</a> but it confused me even more. So far here is what I have:</p>
  <p>The script:</p>
  <pre><code>#!/bin/bash
  declare -A PERSONS
  declare -A PERSON
  PERSON[&quot;FNAME&quot;]='John'
  PERSON[&quot;LNAME&quot;]='Andrew'
  PERSONS[&quot;1&quot;]=${PERSON[@]}
  PERSON[&quot;FNAME&quot;]='Elen'
  PERSON[&quot;LNAME&quot;]='Murray'
  PERSONS[&quot;2&quot;]=${PERSON[@]}
  for KEY in &quot;${!PERSONS[@]}&quot;; do
   TMP=&quot;${PERSONS[&quot;$KEY&quot;]}&quot;
   echo &quot;$KEY - $TMP&quot;
   echo &quot;${TMP[&quot;FNAME&quot;]}&quot;
   echo &quot;${TMP[&quot;LNAME&quot;]}&quot;
  done
  </code></pre>
  <p>The output:</p>
  <pre><code>1 - John Andrew
  John Andrew
  John Andrew
  2 - Elen Murray
  Elen Murray
  Elen Murray
  </code></pre>
  <p>As you can see trying to access a specific index of the $TMP array in the for loop returns the whole array.</p>
  <p><strong>[Q] What do I need to do in order to separately access the &quot;FNAME&quot; and &quot;LNAME&quot; indexes of the $TMP array inside the <code>for</code> loop?</strong></p>
  <p>Thanks.</p>