Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #238239

Re: Bash script problem

From Greg Wooledge <greg@wooledge.org>
Newsgroups linux.debian.user
Subject Re: Bash script problem
Date 2021-08-06 04:10 +0200
Message-ID <CIXt7-2kg-3@gated-at.bofh.it> (permalink)
References (5 earlier) <CIVAZ-1fl-3@gated-at.bofh.it> <CIVAZ-1fl-1@gated-at.bofh.it> <CIVKF-1it-3@gated-at.bofh.it> <CIVUl-1lo-3@gated-at.bofh.it> <CIX9M-1YH-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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

Back to linux.debian.user | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Bash script problem "Gary L. Roach" <garyroach719@gmail.com> - 2021-08-05 02:00 +0200
  Re: Bash script problem Greg Wooledge <greg@wooledge.org> - 2021-08-05 02:10 +0200
    Re: Bash script problem "Gary L. Roach" <garyroach719@gmail.com> - 2021-08-05 05:50 +0200
      Re: Bash script problem john doe <johndoe65534@mail.com> - 2021-08-05 09:00 +0200
      Re: Bash script problem <tomas@tuxteam.de> - 2021-08-05 10:10 +0200
        Re: Bash script problem Greg Wooledge <greg@wooledge.org> - 2021-08-05 13:20 +0200
          test vs. [ [was: Bash script problem] <tomas@tuxteam.de> - 2021-08-05 14:00 +0200
            Re: test vs. [ [was: Bash script problem] Greg Wooledge <greg@wooledge.org> - 2021-08-05 14:40 +0200
              Re: test vs. [ [was: Bash script problem] <tomas@tuxteam.de> - 2021-08-05 15:00 +0200
      Re: Bash script problem Greg Wooledge <greg@wooledge.org> - 2021-08-05 14:30 +0200
  Re: Bash script problem Anssi Saari <as@sci.fi> - 2021-08-05 09:40 +0200
    Re: Bash script problem Tixy <tixy@yxit.co.uk> - 2021-08-05 10:30 +0200
      Re: Bash script problem <tomas@tuxteam.de> - 2021-08-05 10:40 +0200
        Re: Bash script problem Greg Wooledge <greg@wooledge.org> - 2021-08-05 14:00 +0200
          Re: Bash script problem "Gary L. Roach" <garyroach719@gmail.com> - 2021-08-05 22:10 +0200
            Re: Bash script problem Greg Wooledge <greg@wooledge.org> - 2021-08-05 22:20 +0200
              Re: Bash script problem "Gary L. Roach" <garyroach719@gmail.com> - 2021-08-06 17:00 +0200
                Re: Bash script problem <tomas@tuxteam.de> - 2021-08-06 17:10 +0200
            Re: Bash script problem David <bouncingcats@gmail.com> - 2021-08-06 01:40 +0200
              Re: Bash script problem Greg Wooledge <greg@wooledge.org> - 2021-08-06 02:10 +0200
                Re: Bash script problem Polyna-Maude Racicot-Summerside <debian@polynamaude.com> - 2021-08-06 02:20 +0200
                Re: Bash script problem Greg Wooledge <greg@wooledge.org> - 2021-08-06 02:30 +0200
                Re: Bash script problem The Wanderer <wanderer@fastmail.fm> - 2021-08-06 03:50 +0200
                Re: Bash script problem Greg Wooledge <greg@wooledge.org> - 2021-08-06 04:10 +0200
              Re: Bash script problem Polyna-Maude Racicot-Summerside <debian@polynamaude.com> - 2021-08-06 02:10 +0200
                Re: Bash script problem Christian Groessler <chris@groessler.org> - 2021-08-06 02:30 +0200
                Re: Bash script problem Christian Groessler <chris@groessler.org> - 2021-08-06 03:00 +0200
                Re: Bash script problem Greg Wooledge <greg@wooledge.org> - 2021-08-06 03:10 +0200
                Re: Bash script problem David <bouncingcats@gmail.com> - 2021-08-06 03:10 +0200
                Re: Bash script problem David <bouncingcats@gmail.com> - 2021-08-06 03:00 +0200
                Re: Bash script problem <tomas@tuxteam.de> - 2021-08-06 09:00 +0200
              Re: Bash script problem David Wright <deblis@lionunicorn.co.uk> - 2021-08-06 05:10 +0200
                Re: Bash script problem David <bouncingcats@gmail.com> - 2021-08-06 05:50 +0200
              Re: Bash script problem Darac Marjal <mailinglist@darac.org.uk> - 2021-08-06 09:20 +0200
  Re: Bash script problem Tom Browder <tom.browder@gmail.com> - 2021-08-06 01:00 +0200

csiph-web