[Top][All Lists]

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

Re: UUID as Array Keys strangely not possible

From: Dennis Williamson
Subject: Re: UUID as Array Keys strangely not possible
Date: Fri, 25 Jan 2019 22:37:11 -0600

On Fri, Jan 25, 2019, 9:51 PM Robert White <address@hidden wrote:

> On 1/22/19 10:23 PM, Chet Ramey wrote:
> > 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
> >> ...
> >> ...
> >> 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.
> >
> > Do you have some sample UUID data to test this with?
> >
> I'm going to have to provisionally withdraw this report. The problem
> only seems to happen in the custom /init script in my initramfs. Trying
> to recreate it with a simpler script (and the same bash binary) on a
> fully running system using the the UUIDs I collected with blkid doesn't
> have a problem at all. So something "mysterious" is going on.
> The initscript is part of https://sourceforge.net/projects/underdog/ (if
> you care) and is part of my attempt to build a concordance of UUID to
> device to manager (e.g. lvm vs mdadm vs whatever) app. It works well
> except when it doesn't.
> Thanks for the prompt response. If I isolate the test case or the issue
> in general I'll be back. Even just to say never mind if I find a super
> stupid mistake. 8-)
> --Rob White.

I'm not going to try to do a full code review. It took me more time than I
was willing to spend already to find a file that has an associative array
referring to UUIDs in the first place and to put this message together.

Here are a few comments about prototype/init:

In the global scope UUID_TABLE is declared as an indexed array at one point
then an associative array later.

In the get_ (something) function an array element is set violating
separation of get and set.

In that same function, a max_index variable is set to the highest index of
a numeric array then the array is iterated using a C-style for loop. Arrays
in Bash are sparse and the correct way to iterate is to step over the
elements or the indices.

for element in "address@hidden"

for index in "address@hidden"

But it seems you just want to add an element.


There is a variable called AA. I didn't look to see if that means something
but I shouldn't have to. A better name is needed.

Forgive me if I misunderstood anything. It was just a cursory once over.

 Also, I didn't immediately notice what the UUID indexing problem initially
reported is caused by. Except that I played with an indexed array with a
UUID-like index. In that case the index *is* evaluated mathematically so
this may be your problem. That makes sense based on the redefinition I
mentioned above since the second declare will produce an error without
affecting the array.


reply via email to

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