I have been struggling with a new concept to me - associative arrays in a bash script.
Here is simplified version of my code:
#!/bin/bash
declare -A MYID
MYID[hello]=world
tac /home/user/filename | while read -r line; do
MYID[hello]=me
done
echo "${MYID[hello]}"
exit
This is what I thought it would do: 1) declare an associative array called MYID 2) in MYID assign the value world to the key hello 3) read the file /home/user/filename backwards line by line 4) every time it reads a line assign me to the key hello in the MYID array 5) print out "me" and exit
What it does do is print out "world" instead of "me". What am I doing wrong?