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

Re: Bash script problem



On Thu, Aug 05, 2021 at 09:47:04PM -0400, The Wanderer wrote:
> I believe I've hit contexts in which I could use '-print0 | xargs -0'
> but couldn't figure out a way to get the job done with '-exec', because
> I needed the command which was being run to process the output to be a
> pipeline. (I no longer remember the specifics of the tasks involved, so
> I can't explain why this was what I needed.)

I mentioned, in the part of the message you didn't quote, that there
are valid use cases for -print0 | xargs -0.  I only gave one specific
example, but I'm sure there are more.

"It's what I'm used to" is a fair reason, too.  Espcially when you're
writing scripts that you only need to use once.

> The only way I can/could think of to do that with an argument to '-exec'
> involved putting the pipeline sequence into a script and calling that
> via -exec, but that's more unwieldy than I want to work with in most cases.

One of the more advanced techniques looks like this:

find ... -exec bash -c '
  some commands
  go here
' x {} +

You can use this in cases where you might want to -exec a script,
but you don't want to create a second file.  It's not unreasonable
to write... say, about 10 lines of bash code in the indented section.
I'd try to avoid doing any more than that.  Just remember that you've
already used up your single quotes, so you can't put single quotes in
there (unless you write them as '\'').

For more discussion on this topic, please see

https://mywiki.wooledge.org/UsingFind
https://mywiki.wooledge.org/BashProgramming/03


Reply to: