bug-bash
[Top][All Lists]
Advanced

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

Re: Space as a key in an associative array - different behaviours


From: Chet Ramey
Subject: Re: Space as a key in an associative array - different behaviours
Date: Fri, 26 Jan 2018 08:57:47 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:52.0) Gecko/20100101 Thunderbird/52.5.2

On 1/25/18 3:45 PM, Chet Ramey wrote:

> These two commands are basically equivalent. By the time the expression
> evaluation is performed, the expression has undergone word expansion,
> and the expression is "A[ ]++" or "A[ ]=1", respectively. Bash doesn't
> allow blank array subscripts, and when the expression evaluator tries to
> get the value of "A[ ]", it's not seen as a valid array reference.
> 
> (It should display an error message if it's not going to allow it, though.)

The alternative, of course, is to simply allow subscripts consisting only
of whitespace: they would evaluate to 0 in an arithmetic context and as
a string when subscripting associative arrays. I'll look at this.

-- 
``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]