title: Associative Arrays in Bash
body: <p>I am attempting to take a file and store the items from the file into an associative array in bash.  An associative array might not be the best course for my action, but from my research it appears to be a good fit.  I have a file that looks like the following:</p>
  
  <pre><code>personid
  phone
  phone
  phone
  personid
  phone
  phone
  phone
  </code></pre>
  
  <p>Please note, persionid is always 20 digits, and phone is always 10.  There is nothing else in this file, and no whitespace, just one of these per line.  I wanted to map these to an associative array with my key being personid and my value being phone.</p>
  
  <p>The code I've worked on regarding this piece is the following:</p>
  
  <pre><code>declare -A person
  
  while read key; do
  
      if [ ${#key} -eq 20 ] ; then
          personID="$key"
      else
         phone="$key"
      fi
  
      person=( ["$personID"]="$phone" )
  
  done &lt; myFile.txt
  
  for i in "${!person[@]}"
  do
      echo "key: $i"
      echo "value: ${person[$i]}"
  done
  </code></pre>
  
  <p>It will correctly store and print one personID as the key and one phone as the value....but there should be multiple values for phone.  I'm thinking when I assign person, I must be doing that wrong, or have it in the wrong placed.  But I've played around with it for quite sometime now and can't get it right.  Never used associative arrays before, so having a little trouble.  Thanks in advance for the help!</p>