Skip to main content
edited tags
Link
Gilles 'SO- stop being evil'
  • 866.5k
  • 205
  • 1.8k
  • 2.3k
Source Link
Ashwin
  • 453
  • 1
  • 5
  • 11

Error when constructing an associative array

I am trying to construct an associative array in bash

#!/bin/bash
declare -A hero_escore

    hero_escore=( "Invoker_Anti-Mage : -44"
    "Tinker_Nyx Assassin : 32"
    "Troll Warlord_Drow Ranger : 3" )

These are 3 different lines. It is intended to be like that only. But the above code gives an error for each line - Troll Warlord_Drow Ranger : 3: must use subscript when assigning associative array. Is it because it is expecting me to use something like this - [Invoker_Anti-Mage]="-44"? If so is there anyway I can make it work the way I have used in my program using bash 3 or something? I want to construct an associative array with the format that I have given. Is it possible?