I find filter programs that have an "in place" option very useful — for
sed -i or
But wouldn't it be nice if you could do that with any filter?
Meet inplace. Invoke this script as:
inplace COMMAND ... -- FILE ...
and it'll filter each
COMMAND, using the usual trick of writing the output to a temporary file in the same directory and then renaming it over the original (unless the command failed).
inplace sort -u -- channels.conf inplace jpegtran -rotate 90 -- *.jpg
This program is an implementation of the
xargs Unix design pattern: it takes
a command and a separate list of arguments to apply it to.
However, there isn't a standard way to separate the command arguments from the
remaining arguments, so the choice of
-- is rather arbitrary.
Some options I've seen:
COMMAND ... \;.
xargsavoids the problem by taking the list of filenames on stdin (whitespace-separated — which is awkward given that modern filenames can quite reasonably contain whitespace).
- execline used to
COMMAND ... \;, but now uses
COMMAND ... ''(i.e. the empty string).
- GNU parallel uses
COMMAND ... :::, or reads lines from stdin if no
I quite like the
'' solution; having the option to read lines from stdin
is also occasionally useful.