[Top][All Lists]

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

Re: test '-v' - associative vs. normal array discrepancy - a bug ?

From: Chet Ramey
Subject: Re: test '-v' - associative vs. normal array discrepancy - a bug ?
Date: Wed, 19 Nov 2014 16:47:08 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:24.0) Gecko/20100101 Thunderbird/24.6.0

On 11/19/14, 2:59 PM, Jason Vas Dias wrote:
> Thanks to all who replied.
> I would really like -v to do as it documented to do :
> " -v
>    True if the shell variable varname is set (has been assigned a value)
> "
> To me, the fact that -v does not return true if the variable is an array
> and does not have element 0 - or element '0' in the case of assocs -
> means it does not behave as documented.
> Either its behaviour should be changed to return true if an array is
> non-empty (contains ANY non-empty element) or the documentation should
> be changed to document '-v's behaviour for both normal and associative
> arrays.

The problem is that you can only put this stuff in so many places.  The
section on arrays says:

"Referencing an array variable without a  subscript
is equivalent to referencing element zero."

If you want to use -v to check whether or not an arbitray variable has
a value, use var[@].  Scalars accept the @ subscript, and it works for
unset variables as well.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/

reply via email to

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