Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #16339
| From | Chet Ramey <chet.ramey@case.edu> |
|---|---|
| Newsgroups | gnu.bash.bug |
| Subject | Re: test -v with array elements |
| Date | 2020-06-01 09:37 -0400 |
| Organization | ITS, Case Western Reserve University |
| Message-ID | <mailman.900.1591018687.2541.bug-bash@gnu.org> (permalink) |
| References | <CAJq09z4cbksdvTmvZPRryLiLaB34G18ZM9ORECLMoExX2RxjgQ@mail.gmail.com> <abbc5535-5054-07e6-cc9f-7e6300bbe9de@case.edu> |
On 5/29/20 4:00 PM, Luiz Angelo Daros de Luca wrote: > 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? Referring to an array without a subscript is equivalent to referencing element 0. > > $ A=(x) > $ test -v A || echo not defined > > OK This sets A[0]=x > > $ A=() > $ A[1]=1 > $ test -v A || echo not defined > not defined > > Should it? 'test -v A' is equivalent to 'test -v A[0]' Exactly. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU chet@case.edu http://tiswww.cwru.edu/~chet/
Back to gnu.bash.bug | Previous | Next | Find similar
Re: test -v with array elements Chet Ramey <chet.ramey@case.edu> - 2020-06-01 09:37 -0400
csiph-web