You can actually do this with GNU Paral…oh, wait, I forgot that this isn't Stack Overflow and I'm not Ole. But seriously, xargs is pretty powerful by itself; I've seen a number of awkward pipelines using heavyweight tools when xargs would have sufficed.
I bristle when I have to switch from a shell for loop to piping jobs to xargs. For loops are like infix notation (the operator/operation kind of goes in the middle) and xargs is postfix (the op goes on the end).<p><pre><code> for file in *pdf *azw3; do calibre-convert $file $file.epub; done
</code></pre>
vs<p><pre><code> find . -name \*pdf -o -name \*azw3 -print0 | xargs -I {} calibre-convert {} {}.epub
</code></pre>
Something about the former is more natural for my brain to produce. If I want to parallelize, for shell loops my muscle memory very quickly converts the above to<p><pre><code> for file in *pdf *azw3; do calibre-convert $file $file.epub & done; wait
</code></pre>
... but if I have a million files my machine is going to have a bad day, whereas the xargs version is easy to limit to N parallel invocations.<p>I'd really like a shell that lets me define my own sugared versions of shell grammar. I imagine writing a 'forp' that would let me do<p><pre><code> forp $(nproc) file in ...; do ...; done
</code></pre>
and the shell would run up to $(nproc) invocations in parallel. Anybody know of such a shell? (Don't say eshell.)
More often than not, you'll get a better result (often more safely) by writing a small thing which generates the complete command lines for all the tasks which need running. Then once you are happy the right thing will be done, feed the list of commands to GNU parallel or something else which does the same thing.<p>Not only does this approach provide confidence before pulling the trigger, but the list of commands may be retained forever for reference / example. It's also clearer and doesn't get the reader mystified by "shell wizardry", as some people are wont to be.
The phrase "POSIX.2" is archaic. If POSIX is IEEE Std 1003, then "POSIX.1" is IEEE Std 1003.1, "POSIX.2" is IEEE Std 1003.2, and so on.<p>In the first revisions, 1003.1 specified "Core Services" (mostly the C language stuff), and 1003.2 specified "Shell and Utilities". But when the Austin Group formed in 1997, they decided to roll the shell and utilities in to 1003.1. There no longer is a .2; it's been deprecated by 1003.1-2001 and all revisions since then.
Kind of embarrassing, but I never actually learned bash well enough to use it even after a decade of programming. When there was only one pair of feet in the sand, that’s where xargs carried me. Everything from web scrapers, to kubernetes admin, I’ve /only/ used xargs to do all of the variable splicing and parallelism that I need.