[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: test '-v' - associative vs. normal array discrepancy - a bug ?
From: |
Greg Wooledge |
Subject: |
Re: test '-v' - associative vs. normal array discrepancy - a bug ? |
Date: |
Wed, 19 Nov 2014 11:39:12 -0500 |
User-agent: |
Mutt/1.4.2.3i |
On Wed, Nov 19, 2014 at 04:20:51PM +0000, Jason Vas Dias wrote:
> Good day -
> Please could anyone explain why the first command below produces no output:
> $ ( declare -A a=([a]=1); if [ -v a ]; then echo yes; fi )
> $ ( declare -a a=([0]=1); if [ -v a ]; then echo yes; fi )
> yes
In a lot of places, when you use the name of an array without an index,
Bash assumes you mean index 0.
imadev:~$ unset a; declare -a a=([1]=1); test -v a && echo yes
imadev:~$ unset a; declare -A a=([0]=1); test -v a && echo yes
yes
So it's not indexed vs. associative arrays. It's simply the fact that you
used index a instead of index 0, plus the fact that -v a is really -v 'a[0]'.
Does this make -v unusable for arrays? Possibly.
- test '-v' - associative vs. normal array discrepancy - a bug ?, Jason Vas Dias, 2014/11/19
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?,
Greg Wooledge <=
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, Piotr Grzybowski, 2014/11/19
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, Chet Ramey, 2014/11/19
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, Piotr Grzybowski, 2014/11/19
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, Jason Vas Dias, 2014/11/19
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, Greg Wooledge, 2014/11/19
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, Eduardo A . Bustamante López, 2014/11/19
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, Greg Wooledge, 2014/11/19
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, Piotr Grzybowski, 2014/11/19
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, Greg Wooledge, 2014/11/19
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, Piotr Grzybowski, 2014/11/19