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"]}"
Community
  • 1
  • 1
Mandar Pande
  • 12,250
  • 16
  • 45
  • 72
  • 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"]}"` – Mandar Pande Mar 06 '12 at 13:43

1 Answers1

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
Eduardo Ivanec
  • 11,668
  • 2
  • 39
  • 42