[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: -v no longer works for associative arrays
From: |
Greg Wooledge |
Subject: |
Re: -v no longer works for associative arrays |
Date: |
Thu, 13 Oct 2022 11:42:51 -0400 |
On Thu, Oct 13, 2022 at 10:42:02AM -0400, Bryan Roessler wrote:
> Description:
>
> bash-5.2# declare -A a
> bash-5.2# a[foo]=bar
> bash-5.2# [[ -v a[@] ]]; echo $?
> 1
>
> bash-5.1# declare -A a
> bash-5.1# a[foo]=bar
> bash-5.1# [[ -v a[@] ]]; echo $?
> 0
>
> If this is by design I missed it.
unicorn:~$ bash-5.2
unicorn:~$ declare -A a=([@]=at [foo]=bar)
unicorn:~$ [[ -v a[@] ]]; echo $?
0
What are you even trying to do there? Determine whether the associative
array has 1 or more elements? You can use ${#a[@]} for that, just like
with indexed arrays.
unicorn:~$ echo "${#a[@]}"
2
- -v no longer works for associative arrays, Bryan Roessler, 2022/10/13
- Re: -v no longer works for associative arrays, Chet Ramey, 2022/10/13
- Re: -v no longer works for associative arrays, Oğuz, 2022/10/13
- Re: -v no longer works for associative arrays, Chet Ramey, 2022/10/13
- Re: -v no longer works for associative arrays, Oğuz, 2022/10/13
- Re: -v no longer works for associative arrays, Bryan Roessler, 2022/10/13
- Re: -v no longer works for associative arrays, Chet Ramey, 2022/10/13
- Re: -v no longer works for associative arrays, Greg Wooledge, 2022/10/13
Re: -v no longer works for associative arrays,
Greg Wooledge <=