Consider the following bash snippets. In them, I'm creating two associative arrays in different ways, and then printing one of the entries.
Scenario 1. Declaring and assigning in one statement. Works as expected:
make_person() { echo '([firstName]=Bob [lastName]=Black)'; }
declare -A person1=$(make_person)
echo "${person1[firstName]}"
Output:
Bob
Scenario 2. Declaring and assigning on two different lines. No output:
declare -A person2
person2=$(make_person)
echo "${person2[firstName]}"
Output:
Why does Scenario 1 succeed in printing the [firstName] entry while Scenario 2 does not? Are both scenarios defined and expected behaviour?