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: Emanuele Torre
Subject: Re: nounset option: Error message points to the wrong variable when accessing associative arrays
Date: Wed, 10 May 2023 17:25:35 +0200
User-agent: Mutt/2.2.10 (2023-03-25)

On Wed, May 10, 2023 at 02:07:46PM +0000, Baumann, Moritz wrote:
> Configuration Information [Automatically generated, do not change]:
> Machine: x86_64
> OS: linux-musl
> Compiler: gcc
> Compilation CFLAGS: -Os -Wformat -Werror=format-security 
> -Werror=int-conversion -DSYS_BASHRC='/etc/bash/bashrc' -g
> uname output: Linux 9c586e87b370 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri 
> Jan 27 02:56:13 UTC 2023 x86_64 Linux
> Machine Type: x86_64-alpine-linux-musl
> 
> Bash Version: 5.2
> Patch Level: 15
> Release Status: release
> 
> Description:
>         When the nounset option is set, and you try to access a key of an
>         associative array that does not exist, the error message complains
>         about the key being unbound instead of the array variable.
> 
> 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

That is correct behaviour: you set myarray[foo], but you tried to expand
my_array[foo] that is not set.

 emanuele6



reply via email to

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