Re: Executing Shell Pipelines with ?find? _-exec?

Liste des GroupesRevenir à cu shell 
Sujet : Re: Executing Shell Pipelines with ?find? _-exec?
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.unix.shell comp.os.linux.misc
Date : 27. Apr 2024, 20:13:25
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240427110236.112@kylheku.com>
References : 1 2 3
User-Agent : slrn/pre1.0.4-9 (Linux)
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.

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


--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Date Sujet#  Auteur
27 Apr 24 * Executing Shell Pipelines with “find -exec”8Lawrence D'Oliveiro
27 Apr 24 +* Re: Executing Shell Pipelines with “find -exec”6Christian Weisgerber
27 Apr 24 i+* Re: Executing Shell Pipelines with ?find? _-exec?4Robert Heller
27 Apr 24 ii`* Re: Executing Shell Pipelines with ?find? _-exec?3Kaz Kylheku
27 Apr 24 ii `* Re: Executing Shell Pipelines with ?find? _-exec?2Robert Heller
5 May 24 ii  `- Re: Executing Shell Pipelines with ?find? _-exec?1Friedhelm Waitzmann
28 Apr 24 i`- Re: Executing Shell Pipelines with “find -exec”1Lawrence D'Oliveiro
5 May 24 `- Re: Executing Shell Pipelines with “find -exec”1Friedhelm Waitzmann

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal