bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Behaviour of test -v with assoc array and quote character in key


From: Léa Gris
Subject: Re: Behaviour of test -v with assoc array and quote character in key
Date: Tue, 23 Feb 2021 14:03:30 +0100
User-agent: Telnet/1.0 [tlh] (PDP11/DEC)

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

[Prev in Thread] Current Thread [Next in Thread]