[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Associative array keys are not reusable in (( command
From: |
Ilkka Virta |
Subject: |
Re: Associative array keys are not reusable in (( command |
Date: |
Fri, 8 Jan 2021 19:15:13 +0200 |
On Fri, Jan 8, 2021 at 5:44 PM Chet Ramey <chet.ramey@case.edu> wrote:
> On 1/8/21 10:24 AM, Oğuz wrote:
> > This situation is why bash-5.0 introduced the `assoc_expand_once'
> option.
> > But it allows arbitrary command injection.
>
> If you want to run array keys through word expansions, this is one
> potential result. Command substitution is "arbitrary command injection."
>
Let's say I don't want to run the keys through expansions. How
does assoc_expand_once help then, if it doesn't stop the expansion inside
$key?
With the keys in the previous messages, what _seems_ to work is
shopt -u assoc_expand_once
(( assoc[\$k]++ ))
But it only works with assoc_expand_once disabled, and somehow, I'm not
sure if it's safe for more complex keys.
then there's also
x=${assoc[$k]}
assoc[$k]=$(( x + 1 ))
which doesn't seem to be affected by assoc_expand_once but is a bit weary
to use.
- Associative array keys are not reusable in (( command, Oğuz, 2021/01/08
- Re: Associative array keys are not reusable in (( command, Koichi Murase, 2021/01/08
- Re: Associative array keys are not reusable in (( command, Chet Ramey, 2021/01/08
- Re: Associative array keys are not reusable in (( command, Oğuz, 2021/01/08
- Re: Associative array keys are not reusable in (( command, Chet Ramey, 2021/01/10
- 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