Sample Header Ad - 728x90

Dictionary in shell script only showing last associated item

0 votes
1 answer
3103 views
I am trying to use dictionaries and stumbled across a weird behavior. When I create a dictionary like this:
declare -A servers
servers=( ["omega"]="dev" ["delta"]="test" ["beta"]="ppd" ["alpha"]="prd" )


echo "${servers["omega"]}"
The last element "prd" will be printed to the screen, not the first one. Deleting every entry except the first one will result in the correct output. I am not sure what I am doing wrong because every code example I had a look at is using dictionaries like above. Can anyone spot my mistake? Greetings
Asked by Scriptinator (1 rep)
Jan 30, 2020, 12:58 PM
Last activity: Mar 26, 2021, 11:01 AM