help-bash
[Top][All Lists]
Advanced

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

Re: Passing multiple search directories to grep


From: Greg Wooledge
Subject: Re: Passing multiple search directories to grep
Date: Tue, 3 Aug 2021 14:05:20 -0400

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.

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?

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.

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?

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.



reply via email to

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