title: bash associative array read file and set key
body: <p>I would like to read a config file and write it into a array. Everything before the = character should be the key for the array. Unfortunately, the bash does not interpret the variable correctly. </p>
  
  <p>Unfortunately, it takes the variable name one to one.</p>
  
  <pre><code>ary["$key"]='test01 test02 test03'
  </code></pre>
  
  <p>The test config example:</p>
  
  <pre><code>IMAGES=test01 test02 test03
  NEUIMAGE=test1 test2 test3
  </code></pre>
  
  <p>The script:</p>
  
  <pre><code>#!/bin/bash
  
  FILENAME='/testfile'
  
  readarray -t lines &lt; "$FILENAME"
  
  set -x
  
  while IFS== read -r key value; do
      echo $key
      test=ary["$key"]=$value
      ary["$key"]=$value
  done &lt; "$FILENAME"
  
  echo ${ary[@]}
  </code></pre>
  
  <p>The debugging output:</p>
  
  <pre><code>+ IFS==
  + read -r key value
  + echo IMAGES
  IMAGES
  + test='ary[IMAGES]=test01 test02 test03‚
  + ary["$key"]='test01 test02 test03'
  + IFS==
  + read -r key value
  + echo NEUIMAGE
  NEUIMAGE
  + test='ary[NEUIMAGE]=test1 test2 test3'
  + ary["$key"]='test1 test3 test2'
  + IFS==
  + read -r key value
  + echo test1 test3 test2
  test1 test3 test2
  </code></pre>
  
  <p>What do I have to do to interpret the variable? Is there a better solution?</p>
  
  <p>EDIT:</p>
  
  <p>Thanks to @gniourf_gniourf !</p>
  
  <p>Problem solved:</p>
  
  <pre><code>#!/bin/bash
  
  FILENAME='/testfile'
  
  set -x
  
  declare -A ary
  
  while IFS== read -r key value; do
      echo $key
      test=ary["$key"]=$value
      ary["$key"]=$value
  done &lt; "$FILENAME"
  
  echo ${ary[@]}
  </code></pre>
  
  <p>Is there a more elegant way? Or is this already a good variant?</p>