Deutsch   English   Français   Italiano  
<WcWcnTF4lPG60rD7nZ2dnZfqnPidnZ2d@giganews.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!Xl.tags.giganews.com!local-1.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sat, 27 Apr 2024 19:16:55 +0000
MIME-Version: 1.0
From: Robert Heller <heller@deepsoft.com>
Organization: Deepwoods Software
X-Newsreader: TkNews 3.0 (1.2.17)
Subject: Re: Executing Shell Pipelines with ?find? _-exec?
In-Reply-To: <20240427110236.112@kylheku.com>
References: <v0ig4l$96sa$1@dont-email.me>? 
    <slrnv2q034.ihq.naddy@lorvorc.mips.inka.de>? 
    <lpGcnb38WpoNg7D7nZ2dnZfqnPGdnZ2d@giganews.com> 
    <20240427110236.112@kylheku.com>
Newsgroups: comp.unix.shell,comp.os.linux.misc
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
              charset="us-ascii"
Originator: heller@sharky4.deepsoft.com
Message-ID: <WcWcnTF4lPG60rD7nZ2dnZfqnPidnZ2d@giganews.com>
Date: Sat, 27 Apr 2024 19:16:55 +0000
Lines: 61
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-HFM1UdVXqXoTglsKNpsJCk6YhF8+svZX09AX9H6X6t8bQJmgtGlhedKImbwwJaAQA2ORHphT4/7IVFT!n6gpqbx+Sa+gSweok7BygMyZZxFOO1SxwUeb2cTZKvkZq6SyHRK3JfvRCO9AOVgTEqwTcDLBLwY6!s94=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
Bytes: 3926

At Sat, 27 Apr 2024 18:13:25 -0000 (UTC) Kaz Kylheku <643-408-1753@kylheku.com> wrote:

> 
> On 2024-04-27, Robert Heller <heller@deepsoft.com> wrote:
> > At Sat, 27 Apr 2024 13:40:52 -0000 (UTC) Christian Weisgerber <naddy@mips.inka.de> wrote:
> >> A few days ago, Helmut Waitzmann pointed out a better solution over
> >> on the German group:
> >> 
> >>   find . -name \*.blend -exec sh -c \
> >>     '[ $(blendfile_version "$1" | jq -r .version ) \> 304 ]' sh {} \; \
> >>     -print
> >> 
> >> You pass the filename as a positional parameter and reference it
> >> as such in the command string.
> >
> > Another option: find ... -print0 | xargs -0 -n 1 ...
> 
> And what is the ... after xargs? The goal of the command is
> to print only those files F that individually satisfy the predicate
> "[ $(blendfile_version F | jq -r .version) -gt 304 ]".
> 
> xargs will turn groups of files into command arguments, so
> now you have to iterate over them; something like:
> 
>   .. | xargs sh 'for x in "$@"; do\
>                    [ $(blendfile_version "$x" | \
>                        jq -r .version ) -gt 304 ] && printf "%s\n" "$x"
>                  done'
> 
> It doesn't seem like an improvement. It does at least as much work
> (still has to dispatch blendfile_version as many times as there
> are files).  It's more verbose, and uses GNU extensions.

The '-n 1' tells xargs to run the command given to xargs with only one file at 
a time.  There is no need for the "for x in "$@"; do...".

find . -name '*.blend' -print0 | xargs -0 -n 1 'sh [ $(blendfile_version "$1" | \
    jq -r .version ) -gt 304 ] && printf "%s\n" "$1"'


The combination of find's -print0 and xargs -0 is to pass the names as nul
terminated strings rather then newline separated strings. This avoids problems
with file names containing characters that the shell with try to make sense of
(eg spaces, etc.).

> 
> If extensions are allowed, we can just drop find entirely and use
> use double star globbing in Bash or any other shell that has it:
> 
>   for x in **/*.blend; do
>     [ $(blendfile_version "$x" | jq -r .version ) -gt 304 ] && printf "%s\n" "$x"
>   done
> 
> 

-- 
Robert Heller             -- Cell: 413-658-7953 GV: 978-633-5364
Deepwoods Software        -- Custom Software Services
http://www.deepsoft.com/  -- Linux Administration Services
heller@deepsoft.com       -- Webhosting Services