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: Robert White
Subject: Re: UUID as Array Keys strangely not possible
Date: Sat, 26 Jan 2019 07:55:02 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0

On 1/26/19 4:37 AM, Dennis Williamson wrote:
On Fri, Jan 25, 2019, 9:51 PM Robert White <rwhite@pobox.com 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
...
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.

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 "${array[@]}"

for index in "${!array[@]}"

But it seems you just want to add an element.

array+=(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.



Yeah, that was me trying to hack around the UUID problem.

I tried to reduce the UUID index errors into a meta index where I look for the UUID in an indexed array and append it to the array if not found, and then use that index as the index elsewhere. It's a dumb trick that I used once in another environment (NexExpert, circa 1995 if you care) that didn't give me valid associative arrays.

The script as it currently exists is currently a confused abortion of hackery surrounding the original subscript errors.

But it started because just using the UUIDs as the associative array was crashing... but only on some UUIDs.

It started clean but it got ugly damn fast when the UUID errors initally showed up.

(so the get_ is a find-or-append-then-return-index() nonsense thing.)

It turned into a game of wac-a-mole.

Like I said, it got ugly. ha ha ha.

I've now got to back out the worst of the hacks and figure out why the original ${DEVICE_TABLE[$UUID]} style indexing failed in the init script when it clearly works with my collected UUIDs in regular user contexts.

I've already gone through and replaced or refactored all the double-square-bracket evaluations with single-square-bracket expressions, and otherwise looked for any explicit arithmatic contexts that might be confusing the issue.

The current state is hideous, which is why I need to back out the hacks; but the ugly hacks went in because of the indexing errors, so something is fishy.

--Rob.



reply via email to

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