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 ${!UUID_TABLE[@]}
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 [email protected] http://tiswww.cwru.edu/~chet/