bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: nounset option: Error message points to the wrong variable when acce


From: Baumann, Moritz
Subject: RE: nounset option: Error message points to the wrong variable when accessing associative arrays
Date: Wed, 10 May 2023 20:08:48 +0000

> ⚠️ STOP USING [[ -v "assoc[$key]" ]]! DO NOT USE IT! ⚠️
> 
> [...]
>
> Use  [[ -v 'assoc[$key]' ]]  instead, so that -v can expand the variable
> correctly by itself:

Thank you for the warning, I somehow forgot about this behavior even though
the manual mentions it explicitly.

> Also, especially since you are using $1 in this case, you probably want
> to make sure that $1 is not empty, because oterwise  assoc[$key]  is an
> error.

Fortunately, I had already validated that in the part I omitted.

reply via email to

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