help-bash
[Top][All Lists]
Advanced

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

Re: What has been changed in [[ -v x[@] ]]?


From: alex xmb ratchev
Subject: Re: What has been changed in [[ -v x[@] ]]?
Date: Mon, 17 Jul 2023 08:27:59 +0200

On Mon, Jul 17, 2023, 7:04 AM Peng Yu <pengyu.ut@gmail.com> wrote:

> Hi,
>
> I see the following change in the behavior of [[ -v x[@] ]]. Why is
> there such a change?
>
> What is the most efficient way to test whether an associated array is
> empty, unset or does not exist?
>

! (( ${#arr[@]} )) && echo existing

$ bash --version
> GNU bash, version 5.1.8(1)-release (x86_64-apple-darwin18.7.0)
> Copyright (C) 2020 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later <
> http://gnu.org/licenses/gpl.html>
>
> This is free software; you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.
> $ declare -A x=([a]=1 [b]=2)
> $ [[ -v x[@] ]]; echo $?
> 0
>
> ----
>
> $ bash --version
> GNU bash, version 5.2.15(1)-release (x86_64-apple-darwin21.6.0)
> Copyright (C) 2022 Free Software Foundation, Inc.
> License GPLv3+: GNU GPL version 3 or later <
> http://gnu.org/licenses/gpl.html>
>
> This is free software; you are free to change and redistribute it.
> There is NO WARRANTY, to the extent permitted by law.
> $ declare -A x=([a]=1 [b]=2)
> $ [[ -v x[@] ]]; echo $?
> 1
>
>
> --
> Regards,
> Peng
>
>


reply via email to

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