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: 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.


reply via email to

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