Skip to content
Advertisement

Does shell map restrict the key format?

 a=()
 a["/dev"]=3
 echo ${a["/dev"]} 

Run the above code will get error:

syntax error: operand expected (error token is "/dev") 

If I modify key=’dev’, it works. So, the key only can be a simple string?

Advertisement

Answer

You must declare the array associative first:

declare -A a
a["/dev"]=3
echo ${a["/dev"]}
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement