Deutsch English Français Italiano |
<20240427110236.112@kylheku.com> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!weretis.net!feeder9.news.weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Kaz Kylheku <643-408-1753@kylheku.com> Newsgroups: comp.unix.shell,comp.os.linux.misc Subject: Re: Executing Shell Pipelines with ?find? _-exec? Date: Sat, 27 Apr 2024 18:13:25 -0000 (UTC) Organization: A noiseless patient Spider Lines: 42 Message-ID: <20240427110236.112@kylheku.com> References: <v0ig4l$96sa$1@dont-email.me> <slrnv2q034.ihq.naddy@lorvorc.mips.inka.de> <lpGcnb38WpoNg7D7nZ2dnZfqnPGdnZ2d@giganews.com> Injection-Date: Sat, 27 Apr 2024 20:13:26 +0200 (CEST) Injection-Info: dont-email.me; posting-host="3b57bd4a52cf8401a2be99b40cc84e8f"; logging-data="545074"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19dJA77f12v6Oo9zN9XC3xWd4fStd9RZZg=" User-Agent: slrn/pre1.0.4-9 (Linux) Cancel-Lock: sha1:pFsdyupeaKIua6SBYX3rJ5CDv1Q= Bytes: 2666 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