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.

1

1 Answer 1

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"]}
Sign up to request clarification or add additional context in comments.

2 Comments

Would you please provide a way to iterate this as key value :)
this was already answered here : stackoverflow.com/questions/3112687/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.