[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.
- Re: Associative array keys are not reusable in (( command, (continued)
- Re: Associative array keys are not reusable in (( command, Oğuz, 2021/01/10
- Re: Associative array keys are not reusable in (( command, Chet Ramey, 2021/01/11
- Re: Associative array keys are not reusable in (( command, Greg Wooledge, 2021/01/11
- Re: Associative array keys are not reusable in (( command, Chet Ramey, 2021/01/11
- Re: Associative array keys are not reusable in (( command, Oğuz, 2021/01/11
- Re: Associative array keys are not reusable in (( command, Chet Ramey, 2021/01/11
- Re: Associative array keys are not reusable in (( command, Greg Wooledge, 2021/01/11
- Re: Associative array keys are not reusable in (( command, Oğuz, 2021/01/11
- Re: Associative array keys are not reusable in (( command, Léa Gris, 2021/01/11
- Re: Associative array keys are not reusable in (( command, Léa Gris, 2021/01/11
- Re: Associative array keys are not reusable in (( command,
Greg Wooledge <=
- Re: Associative array keys are not reusable in (( command, Oğuz, 2021/01/11