Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16319 > unrolled thread

test -v with array elements

Started byLuiz Angelo Daros de Luca <luizluca@gmail.com>
First post2020-05-29 17:00 -0300
Last post2020-05-29 17:00 -0300
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  test -v with array elements Luiz Angelo Daros de Luca <luizluca@gmail.com> - 2020-05-29 17:00 -0300

#16319 — test -v with array elements

FromLuiz Angelo Daros de Luca <luizluca@gmail.com>
Date2020-05-29 17:00 -0300
Subjecttest -v with array elements
Message-ID<mailman.651.1590782471.2541.bug-bash@gnu.org>
Hello,

While using test -v, I noticed that it returns false when I use it
with a sparse or empty array. I need to add [@] or [index] to have it
return true.

Is this expected? If so, it is not documented. It only has:

"True if the shell variable varname is set (has been assigned a value)."

I'm using GNU bash, version 5.0.16(1)-release (x86_64-pc-linux-gnu)

$ A=()
$ test -v A || echo not defined
not defined

Should it?

$ A=(x)
$ test -v A || echo not defined

OK

$ A=()
$ A[1]=1
$ test -v A || echo not defined
not defined

Should it? 'test -v A' is equivalent to 'test -v A[0]'

$ test -v A[1] || echo not defined
$ test -v A[2] || echo not defined
not defined

if index is specified, it would be ok to have it return false. It
would be a better way to test if an array contains a value (other than
variable expansion).

$ test -v A[@] || echo not defined

This only fails when A is an empty array, which might be correct.

Regards,
---
     Luiz Angelo Daros de Luca
            luizluca@gmail.com

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web