2

Possible Duplicate:
How to define hash tables in bash?

Perl hash equivalent in bash ? Please let me know.

Following code is working perfectly in korn shell, however not in bash [3.2 version], getting error for typeset.

#!/bin/ksh 
typeset -A newmap 
name="mandar"
id="111515" 
newmap["name"]=$name
newmap["id"]=$id 
echo "${newmap["id"]}"
1
  • Following code is working perfectly in korn shell, however not in bash [3.2 version], getting error for typeset. #!/bin/ksh typeset -A newmap name="mandar" id="111515" newmap["name"]=$name newmap["id"]=$id echo "${newmap["id"]}" Commented Mar 6, 2012 at 13:43

1 Answer 1

1

Use declare -A instead of typeset -A if you're running Bash 4 or better. I tested it and it works correctly that way.

Alternatively you could test for bash and create an alias so you can run the rest of the script unmodified (probably):

alias typeset=declare
Sign up to request clarification or add additional context in comments.

1 Comment

@mandy: you're right, I forgot to say that this works on Bash 4 and higher. Mine's Bash 4.2.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.