bug-bash
[Top][All Lists]
Advanced

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

wrong variable name in error message about unbound variable?


From: Christoph Anton Mitterer
Subject: wrong variable name in error message about unbound variable?
Date: Tue, 17 Oct 2023 03:06:40 +0200
User-agent: Evolution 3.50.0-1

Hey.

On 5.2.15 I've noticed the following:

$ set -u
$ [ -n "${array[key]+is_set}" ] && echo is set || echo not set
bash: key: unbound variable
$ [[ -v array[key] ]] && echo is set || echo not set
bash: key: unbound variable

$ declare -A array
$ [ -n "${array[key]+is_set}" ] && echo is set || echo not set
not set
$ [[ -v array[key] ]] && echo is set || echo not set
not set

Once array is declared (not even anything of it set yet) it gives
already no unbound error.

So shouldn't the error message refer to "array" as the unbound
variable? Or perhaps both "array[key]"?
Because the problem isn't that no key named "key" exists.


And beyond that:
POSIX says:
> -u
>    When the shell tries to expand an unset parameter other than the
>    '@' and '*' special parameters, it shall write a message to
>    standard error and the expansion shall fail with the consequences
>    specified in Consequences of Shell Errors.

But just declaring the var, doesn't make it set... so shouldn't it
still give an error message (which it does when using a non-array
variable that is declared but not set)?


Cheers,
Chris.



reply via email to

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