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: Koichi Murase
Subject: Re: Associative array keys are not reusable in (( command
Date: Fri, 8 Jan 2021 20:20:55 +0800

2021年1月8日(金) 20:07 Oğuz <oguzismailuysal@gmail.com>:
> On Fri, Jan 8, 2021 at 2:14 PM Koichi Murase <myoga.murase@gmail.com> wrote:
>> There is no reason to introduce a different expansion rule of
>> `((...))' from that of `$((...))'.
>
> But there already is a different expansion rule. While `((
> assoc['$key']++ ))' works, `: $(( assoc['$key']++ ))' fails with a
> bad subscript error.

Actually, that inconsistency has been fixed in Bash 5.1 to match with
the behavior of `$(( assoc['$key']++ ))', i.e., now in Bash 5.1, `((
assoc['$key']++ ))' doesn't work either.  So, `(( assoc[\$key]++ ))'
is the only working way to access the associative array in the
arithmetic command of the form `(( ... ))'.  Or, maybe you could write
`let 'assoc[$key]++'`.

--
Koichi



reply via email to

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