bug-bash
[Top][All Lists]
Advanced

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

Re: Associative array keys are not reusable in (( command


From: Greg Wooledge
Subject: Re: Associative array keys are not reusable in (( command
Date: Mon, 11 Jan 2021 10:00:21 -0500
User-agent: Mutt/1.10.1 (2018-07-13)

On Mon, Jan 11, 2021 at 03:50:40PM +0100, Léa Gris wrote:
> safe_arith_index=${x@Q}
> declare -p safe_arith_index
> > declare -- safe_arith_index="'y[\$(date >&2)0]'"
> (( aa[$safe_arith_index]++ ))
> declare -p aa
> > declare -Ai aa=(["y[\$(date >&2)0]"]="3" )

OK, that one has potential, since it can be inlined as well.

unicorn:~$ declare -A aa
unicorn:~$ x='y[$(date >&2)0]'
unicorn:~$ aa[$x]=1
unicorn:~$ (( aa[${x@Q}]++ ))
unicorn:~$ declare -p aa
declare -A aa=(["y[\$(date >&2)0]"]="2" )

Obviously you'd need printf -v tmp %q "$x" if you're running bash older
than 4.4... or just use the tmp=${aa[$x]} workaround.



reply via email to

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