[Top][All Lists]

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

Re: 4.4 change in behavior from 4.3: how to catch unset when using ${#le

From: Dan Douglas
Subject: Re: 4.4 change in behavior from 4.3: how to catch unset when using ${#length}
Date: Tue, 1 Nov 2016 04:57:59 -0500

On Mon, Oct 24, 2016 at 8:25 AM, Chet Ramey <address@hidden> wrote:
> On 10/21/16 5:41 PM, L. A. Walsh wrote:
>> On 4.3 and earlier, at least on arrays, one could have
>> the illusion of this working w/o complaint -- and returning
>> 0 when the array was 0-len or unset, or the array length,
>> otherwise:
>>  echo address@hidden:-0}
>> But I note it only seemed to work in arrays, and in 4.4 gets a
>> syntax error:
>>  echo address@hidden:-0}   bash: address@hidden:-0}: bad substitution
> Because it is a syntax error, and if it were not it would be ambiguous.
> The ${param:-word} word expansion takes a parameter, not another word
> expansion, as the object to be expanded.

On a possibly related note, would you consider adjusting +, :+, -, :-,
as in "address@hidden" to align with the meaning of [[ -v address@hidden ]] as
discussed in https://lists.gnu.org/archive/html/bug-bash/2014-11/msg00099.html
? I've always felt the best use of that expansion would be to test for
a defined array (or any set array element other than arr[0]).
address@hidden, ${var[0]+word}, and ${var+word} are currently
redundant to my knowledge. The latter two I can understand, but address@hidden
seems inconsistent.

My best interpretation of the current behaviour is that it copies that
of $@, which doesn't really make sense IMO because arrays may be
sparse. All the effects of address@hidden make sense but don't translate
well directly to bash arrays. OTOH [[ -v address@hidden ]] since bash 4.3
makes a lot of sense to me and I think they would translate well to
the corresponding parameter expansions.

reply via email to

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