Suppose some favorite util foo
has a useful switch -n bar
which is almost but not quite what's needed. To get what's needed, one could:
- Edit the source code to add what's needed. (Usually not portable, unless an upstream author likes the edit.)
- Make a shell wrapper script or function to add what's needed -- but unless the syntax of
foo
is very simple, parsing a new or extended switch can be difficult. Not because the function is difficult, but because the parsing might be.
Is there some tool that works like an alias or wrapper function for single switches of utils? Something that would work like:
myfunction() { new code goes here... }
wrap '-n=myfunction bar' foo ... -n 3 ...
Or if the -n
switch will see a lot of use:
myfunction() { new code goes here... }
foo() { wrap '-n=myfunction bar' foo ... -n 3 ... ; }
Or suppose -n bar
only allows bar to be an integer, and we need a little tweak to handle a floating point number, but needn't replace -n
unless it's floating point:
wrap '-n=myfunction bar==fp_only` foo ... -n 3.2 ...
Another use for a wrap
might be to temporarily handle an unfixed bug:
wrap '-n=myfunction bar==x' foo ... -n x ...
...where x
is some value, (or set of values), sure to cause trouble without some judicious pre-parsing and reformatting.
Another use would be to add a switch where none exists, (provided it's made up of existing switch functions, or only effects output):
newswitchcode() { ...code... }
wrap '-p=newswitchcode bar' foo ... -p 3 ...
Note that a wrap
would only be feasible for utils with simple output. Utils with complex internal data pipelines like find
wouldn't be be a good fit.
wrap
util would include some automatic prefab type checking or simple data conversion, (suppose the target util only understands decimal input, but hex would be simper, etc...), which would be more of a pain to do on-the-fly.wrap
what to do with a particular command wouldn't actually be any less complex than writing a wrapping script with ed, vi, emacs, etc.xargs
--xargs
does nothing a data feeder wrapper script couldn't do, butxargs
, despite internally being more complex than a wrapper script, is often more convenient to use than writing such a script would be. Helper utils likexargs
are not universal fixes -- they help sometimes, and it's up to users to decide when.xargs
is a serious hack, and really should be abolished - it breaks the philosophy of *ix utils; it does too much. What it should do is simply convert stdin into a parameter for a util that wasn't written to read from stdin - anything else is hackery that should have been handled with other utils likesed
,awk
,grep
, and so on, possibly with additional invocations of the 'simplexargs
' as needed. [More...]