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: Andreas Schwab
Subject: Re: nounset option: Error message points to the wrong variable when accessing associative arrays
Date: Wed, 10 May 2023 17:27:56 +0200
User-agent: Gnus/5.13 (Gnus v5.13)

On Mai 10 2023, Baumann, Moritz wrote:

> Repeat-By:
>         set -u
>         declare -r -A myarray=( [foo]='bar' )
>         # typo in name of the associative array
>         echo ${my_array[foo]}
>
>         Expected output: bash: my_array: unbound variable
>         Actual output: bash: foo: unbound variable

This is expected.  If the array is an indexed array, the subscript is an
arithmetic expression.  When bash tries to evaluate the subscript, it
finds that foo is unbound.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."



reply via email to

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