It's ugly enough using variable indirection with regular arrays, working with associative arrays is difficult -- I did not find a way to iterate over the keys.
I wonder if all you need is declare -p
:
print_array() { declare -p $1; }
print_array weapons
declare -A weapons='(["Imperial Sword"]="90" ["Tainted Dagger"]="54" ["Edged Shuriken"]="25" ["Straight Sword"]="75" )'
Or, prettier:
print_array() { declare -p $1 | sed 's/[[)]/\n&/g'; }
print_array weapons
declare -A weapons='(
["Imperial Sword"]="90"
["Tainted Dagger"]="54"
["Edged Shuriken"]="25"
["Straight Sword"]="75"
)'