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

2021-02-23 Thread Chet Ramey
On 2/23/21 10:55 AM, Greg Wooledge wrote: Oğuz (oguzismailuy...@gmail.com) wrote: `(( assoc[\$var]++ ))' works fine as usual. unicorn:~$ bash-5.1 unicorn:~$ declare -A hash unicorn:~$ key=\'\] unicorn:~$ hash[$key]=17 unicorn:~$ (( hash[\$key]++ )) unicorn:~$ declare -p hash declare -A hash=([

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

2021-02-23 Thread Oğuz
23 Şubat 2021 Salı tarihinde Greg Wooledge yazdı: > Oğuz (oguzismailuy...@gmail.com) wrote: > > `(( assoc[\$var]++ ))' works fine as usual. > > unicorn:~$ bash-5.1 > unicorn:~$ declare -A hash > unicorn:~$ key=\'\] > unicorn:~$ hash[$key]=17 > unicorn:~$ (( hash[\$key]++ )) > unicorn:~$ declare -

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

2021-02-23 Thread Greg Wooledge
Oğuz (oguzismailuy...@gmail.com) wrote: > `(( assoc[\$var]++ ))' works fine as usual. unicorn:~$ bash-5.1 unicorn:~$ declare -A hash unicorn:~$ key=\'\] unicorn:~$ hash[$key]=17 unicorn:~$ (( hash[\$key]++ )) unicorn:~$ declare -p hash declare -A hash=(["']"]="18" ) unicorn:~$ (( 'hash[$key]'++ ))

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

2021-02-23 Thread Oğuz
23 Şubat 2021 Salı tarihinde Greg Wooledge yazdı: > On Tue, Feb 23, 2021 at 02:03:55PM +0100, Andreas Schwab wrote: > > On Feb 23 2021, Greg Wooledge wrote: > > > > > No amount of quoting will make (( 'assoc[$var]'++ )) work. > > > > (( assoc[var]++ )) > > > > Andreas. > > This is not the same as

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

2021-02-23 Thread Greg Wooledge
On Tue, Feb 23, 2021 at 02:03:55PM +0100, Andreas Schwab wrote: > On Feb 23 2021, Greg Wooledge wrote: > > > No amount of quoting will make (( 'assoc[$var]'++ )) work. > > (( assoc[var]++ )) > > Andreas. This is not the same as assoc[$var]. Yours uses the literal string var as the key, not the

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

2021-02-23 Thread Greg Wooledge
On Tue, Feb 23, 2021 at 02:03:30PM +0100, Léa Gris wrote: > ( > LANG=C > unset var assoc > var=\'\] > declare -Ai assoc > assoc[$var]=1 > assoc[$var]+=1 > ((assoc['$var']++)) > typeset -p assoc > ) This "works" in bash 5.0 but not in Debian's bash 5.1. The -i flag is irrelevant as

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

2021-02-23 Thread Andreas Schwab
On Feb 23 2021, Greg Wooledge wrote: > No amount of quoting will make (( 'assoc[$var]'++ )) work. (( assoc[var]++ )) Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."

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

2021-02-23 Thread Léa Gris
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 q

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

2021-02-23 Thread Greg Wooledge
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 ma

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

2021-02-23 Thread Alex fxmbsw7 Ratchev
yeah i thought so.. thanks On Tue, Feb 23, 2021 at 12:52 PM Léa Gris wrote: > Le 23/02/2021 à 12:17, Alex fxmbsw7 Ratchev écrivait : > > what, sorry, mailing stuff isnt much clear to me, ... its not possible to > > have a var=\'\] ; assoc[$var] ? > > You can if assoc is declared an associative a

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

2021-02-23 Thread Léa Gris
Le 23/02/2021 à 12:17, Alex fxmbsw7 Ratchev écrivait : what, sorry, mailing stuff isnt much clear to me, ... its not possible to have a var=\'\] ; assoc[$var] ? You can if assoc is declared an associative array before: $ (LANG=C; unset var assoc; var=\'\]; assoc[$var]=hello; typeset -p assoc)

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

2021-02-23 Thread Alex fxmbsw7 Ratchev
what, sorry, mailing stuff isnt much clear to me, ... its not possible to have a var=\'\] ; assoc[$var] ? On Mon, Feb 22, 2021 at 5:48 PM Chet Ramey wrote: > On 2/15/21 1:28 PM, Daniel Gröber wrote: > > > On Mon, Feb 15, 2021 at 09:11:48AM -0500, Chet Ramey wrote: > >> `test' is always going to

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

2021-02-22 Thread Chet Ramey
On 2/15/21 1:28 PM, Daniel Gröber wrote: On Mon, Feb 15, 2021 at 09:11:48AM -0500, Chet Ramey wrote: `test' is always going to be problematic here because, as a shell builtin, its arguments undergo a round of word expansions before it's invoked. It's difficult to reliably detect the closing bra

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

2021-02-15 Thread Daniel Gröber
Hi Greg and Chet, On Mon, Feb 15, 2021 at 08:48:15AM -0500, Greg Wooledge wrote: > Do it this way instead: > > unicorn:~$ mytest() { array[$1]=123; test -v 'array[$1]'; echo "$?"; } Ah! I didn't know test would exand that '$1' in there, cool. > Yours expands $1 first, then passes array["] as an

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

2021-02-15 Thread Chet Ramey
On 2/14/21 6:27 PM, Daniel Gröber wrote: Hi list, I've found what I belive to be a bug in how `test -v` expands the key in an associative array. The following minimal test case demonstrates the problem: declare -A array mytest () { array["$1"]=123 test

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

2021-02-15 Thread Greg Wooledge
On Mon, Feb 15, 2021 at 12:27:42AM +0100, Daniel Gröber wrote: > I've found what I belive to be a bug in how `test -v` expands the key in an > associative array. The following minimal test case demonstrates the > problem: > > declare -A array > > mytest () { > array["$1"]=

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

2021-02-14 Thread Daniel Gröber
Hi list, I've found what I belive to be a bug in how `test -v` expands the key in an associative array. The following minimal test case demonstrates the problem: declare -A array mytest () { array["$1"]=123 test -v array["$1"] printf 'test -v array