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