[Top][All Lists]

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

Re: test -v for array does not work as documented

From: Chet Ramey
Subject: Re: test -v for array does not work as documented
Date: Wed, 19 Feb 2020 11:27:54 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.5.0

On 2/19/20 11:18 AM, Ulrich Mueller wrote:
>>>>>> On Wed, 19 Feb 2020, Chet Ramey wrote:
>> On 2/19/20 7:00 AM, Ulrich Mueller wrote:
>>> Bash Version: 5.0
>>> Patch Level: 16
>>> Release Status: release
>>> Description:
>>> The GNU Bash Reference Manual Version 5.0 says about test -v:
>>> '-v VARNAME'
>>> True if the shell variable VARNAME is set (has been
>>> assigned a value).
>>> However, it doesn't always return true when VARNAME is an
>>> (indexed or associative) array that has been assigned a value.
>> If you refer to an array variable without the subscript, it's equivalent
>> to referencing element 0.
> That doesn't seem obvious from the documentation for -v.

It's in Arrays:

"Referencing an array variable without a subscript is equivalent to ref-
 erencing the array with a subscript of 0."

> So, is there any syntax that allows to test if a value has been assigned
> to the array variable? 

[ -v array[@] ]

> Especially, to distinguish VARNAME=() (empty
> array) from VARNAME being unset?

There's little to distinguish them: neither has a subscript that's been
assigned a value.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    address@hidden    http://tiswww.cwru.edu/~chet/

reply via email to

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