This is my $a
output:
[root@node1 ~]# echo "${a}"
/dev/vdc1 /gfs1
/dev/vdd1 /elastic
mfsmount /usr/local/flytxt
I gotta store these in an associative array fsmounts
with first column as keys and second col as value.
This is my code for that:
declare -A fsmounts
echo "$a" | while read i ; do key=$(echo "$i" | awk '{print $1}'); value=$(echo "$i" | awk '{print $2}');fsmounts[$key]=$value; done;
But when I try to print outside the loop with
[root@node1 ~]# echo ${fsmounts[/dev/vdb1]}
Blank is the output. I think the associative array fsmounts is not actually storing values. Please help me.
But I can actually able to echo fsmounts[$key]
inside the loop. See this:
echo "$a" | while read i ; do key=$(echo "$i" | awk '{print $1}'); value=$(echo "$i" | awk '{print $2}');fsmounts[$key]=$value; echo ${fsmounts[$key]}; done;
/gfs1
/elastic
/usr/local/flytxt