Bash 4.3.30
Suppose you have the following code:
#!/bin/bash
declare -A map
f() {
map[x]=a
map[y]=b
}
g() {
for k in "${!map[@]}"
do
echo "$k --> ${map[$k]}"
done
}
f
g
This outputs
x --> a
y --> b
If I change the above mentioned program to f | g
it outputs nothing.
I supposed declaring the associative array in global scope would allow me to access its values anytime and anywhere I wanted. I've read about strange problems with pipeline and scope but I've been unable to figure out a solution.