bug-bash
[Top][All Lists]
Advanced

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

Re: UUID as Array Keys strangely not possible


From: Chet Ramey
Subject: Re: UUID as Array Keys strangely not possible
Date: Wed, 23 Jan 2019 11:35:24 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.4.0

On 1/22/19 3:32 PM, Robert White wrote:
> Howdy,
> 
> The following cannot work because, for some reason, the array subscript
> parser insists on doing math on array indices even when the array is
> associative instead of numeric
> 
> typeset -A UUID_TABLE
> ...
> UUID_TABLE+=( [${SOME_UUID}]=${SOME_VALUE} )
> ...
> some_command ${UUID_TABLE[${SOME_UUID}]}
> 
> The parser and evaluator insist on doing math on ${SOME_UUID} no matter how
> its quoted or whatever. This seems extremely wrong.

I can't reproduce this. Given this script:

$ cat ./x18
typeset -A UUID_TABLE

while read SOME_UUID;
do
        SOME_VALUE=42
        UUID_TABLE+=( [${SOME_UUID}]=${SOME_VALUE} )

        echo \${\UUID_TABLE\[${SOME_UUID}]} '<-' ${UUID_TABLE[${SOME_UUID}]}
done < ./x18.in

for f in address@hidden
do
printf "<%s> <%s>\n" "$f" "${UUID_TABLE[$f]}"
done

where the input file contains a list of UUIDs, one per line, I don't
see any arithmetic evaluation taking place. In fact, the expression
evaluator is never called.

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