help-bash
[Top][All Lists]
Advanced

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

Passing multiple search directories to grep


From: hancooper
Subject: Passing multiple search directories to grep
Date: Tue, 03 Aug 2021 20:26:54 +0000

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Tuesday, August 3, 2021 6:05 PM, Greg Wooledge <greg@wooledge.org> wrote:

> On Tue, Aug 03, 2021 at 05:31:58PM +0000, hancooper wrote:
>
> > How can I determine if there are empty elements in an array?
>
> Iterate over the entire array. Set a flag variable (pseudo-boolean)
> before the loop, and flip it (and break out of the loop) if you find
> an empty element.

The plan would be to get a list of indices in the array where the empty
elements occur.  Such function is useful when debugging code.

> But the real question is -- why? Why are you performing this check?
> Does having an empty element in your list break something? If so,
> what does it break? Are there other cases that break things as well?

I am debugging and think they are empty elements that should not be there.

> Maybe the check for emptiness isn't the best solution to whatever
> problem you're having. Maybe you really want to check whether each
> element is an existing directory name.

Already done that, but it is likely that some empty elements have been
introduced because of some errors in the coding or design.

> Next, what are you going to do if you do find an empty or otherwise
> erroneous item in the array? Do you need to abort the whole script?
> Do you simply skip this item during processing later on? Do you remove
> it from the array?

If I find an empty element, I need to see how it was introduced, fix the
code so it will not happen.  Have no plan to remove it from the array,
because it would only be a superficial way to solve the problem.


> Finally, where did your data come from, and how did you get the items
> into the array variable? Could you filter out the empty or otherwise
> erroneous data items while you're populating the array, never putting
> them into the array in the first place? That's preferred over removing
> items from an array in many cases.

Yes, never putting them into the array in the first place is the real solution
to the problem.  But somehow I was not able to ensure that for all situations
of use.





reply via email to

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