On 1/25/18 8:48 AM, Tomasz Warniełło wrote:

> Bash Version: 4.4
> Patch Level: 12
> Release Status: release
> 
> Description:
> When trying to assign to a space key of an associative array,
> the result differs with regards to the way the operation is performed.
> 1. ((A[$a]++))
> 2. let "A[' ']++"
> 3. A[" "]=1
> 
> I've asked a question about this here:
> https://unix.stackexchange.com/questions/419488/bash-space-as-a-key-in-an-assoc$
> 
> Repeat-By:
> 1.
> $ unset A; a=" ";declare -A A; ((A[$a]++)); declare -p A
> declare -A A
> 
> 2.
> $ unset A; a=" ";declare -A A; let "A[$a]=1"; declare -p A
> declare -A A

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.)

Chet

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

Reply via email to