bug-bash
[Top][All Lists]
Advanced

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

Re: Compare 2 arrays.


From: Bill Gradwohl
Subject: Re: Compare 2 arrays.
Date: Wed, 30 May 2012 10:14:42 -0600

On Wed, May 30, 2012 at 6:33 AM, Greg Wooledge <wooledg@eeg.ccf.org> wrote:

>
> Hacks like this are precisely why I stress that such functions *should
> not* be written in bash.  If you want to compare two arrays, use a loop,
> without wrapping a function around it.  That way you have access to the
> arrays directly, by their actual names, in the actual context where they
> are defined.
>

The term hack is used when something is in dispute - is it a bug or a
feature? If a bug, has it been declared so and will it get fixed? So many
things in bash are undocumented so the complete feature list is
indeterminate.

So, If I have several arrays to test, I should duplicate the code once for
each array?
I shouldn't put it into a function but instead I should reinvent the wheel
every time I need this?

Admittedly, bash doesn't go out of its way to highlight this technique, but
it does work.

What say you Chet? Bug or feature? There is no middle ground.


> The only Bourne-family shell that can manipulate arrays whose names are
> passed to a function is ksh93, with its "nameref" command.  Bash has
> nothing analogous to that yet.
>

I believe we're quibbling over the officialness of the solution I provided
to the poster. Obviously bash does support a way of manipulating a foreign
array. I'd like it to be more obvious with something like a nameref as you
suggest, but it's not there.

Every disto I know of uses bash as its default. That's why people use it -
because its suggested by the disto assemblers and because it's there. Bash
is part of the GNU family and many people mistakenly think of GNU as Linux.
By extension, bash has tremendous mind share, is prominently featured and
is what people expect. In the 12 years I've used Linux exclusively, I've
never used any shell but bash.

I wish bash had something akin to C pointers and address arithmetic.
I wish it had pass by reference.
I wish it had a C style prototype as a function definition.
I wish I could set a shopt that would fail a script for an undeclared
variable.
I wish it could return more than just an 8 bit return code.
I wish it had a more robust concept of name space so variables wouldn't
bump into each other.
I wish local really meant local and something further on down the call
chain couldn't access it.
I wish sub functions were hidden from the outside world and only accessible
from within the containing function.

I wish bash had lots of things it doesn't, and yet it does a fine job as a
command interpreter. I have to find alternatives for what I want or need,
but they are there.

...there are dark corners in the Bourne shell, and people use all of them.
-- Chet Ramey

I'm just using one of those dark corners.

-- 
Bill Gradwohl


reply via email to

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