2

I am trying to declare a hash map in shell script containing a file path as key and some variable as value. Something like this

fileVarMap=( ["Dir1/file1.txt"]="myVar1"  ["Dir2/file2.txt"]="myVar2" )

I am getting an Error called...syntax error: invalid arithmetic operator

How can this be achieved?

Thanks in Advance.

Aryan
  • 1,767
  • 2
  • 22
  • 39

1 Answers1

3

If you are using Bash, man page says :

Associative arrays are created using declare -A name.

So, you should try this :

declare -A fileVarMap
fileVarMap=( ["Dir1/file1.txt"]="myVar1"  ["Dir2/file2.txt"]="myVar2" )
echo ${fileVarMap["Dir1/file1.txt"]}
Eric Citaire
  • 4,355
  • 1
  • 29
  • 49