Keys with spaces in Bash associative arrays
<p>I'm trying to read a structured file into an associative array in Bash. The file stores in each line a person name and a person address. For example:</p>
<pre><code>person1|address1
person2|address2
...
personN|addressN
</code></pre>
<p>I am using the script below.</p>
<pre><code>#!/bin/bash
declare -A address
while read line
do
    name=`echo $line | cut -d '|' -f 1`
    add=`echo $line | cut -d '|' -f 2`
    address[$name]=$add
    echo &quot;$name - ${address[$name]}&quot;
done &lt; adresses.txt

for name in ${!address[*]}
do
    echo &quot;$name - ${address[$name]}&quot;
done
</code></pre>
<p>The script work properly. However, in the FOR loop, i'm having some problems when the person name has spaces (For example &quot;John Nobody&quot;). How can I fix this?</p>