Le 23/02/2021 à 13:55, Greg Wooledge écrivait :
On Tue, Feb 23, 2021 at 12:17:10PM +0100, Alex fxmbsw7 Ratchev wrote:
what, sorry, mailing stuff isnt much clear to me, ... its not possible to
have a var=\'\] ; assoc[$var] ?

It should work for simple assignment and retrieval.

You need to add quotes for [[ -v 'assoc[$var]' ]] to work, and math
contexts are dodgy as hell.  No amount of quoting will make
(( 'assoc[$var]'++ )) work.  If you want to increment the value of
this array element, you'll need to retrieve it into a temporary string
variable, increment that, and then copy it back into the array.



Works, if you declare your associative array with A and i flags:

(
  LANG=C
  unset var assoc
  var=\'\]
  declare -Ai assoc
  assoc[$var]=1
  assoc[$var]+=1
  ((assoc['$var']++))
  typeset -p assoc
)

Output:

declare -Ai assoc=(["']"]="3" )

--
Léa Gris


Reply via email to