Suppose you tried something like this:
$ paste ../data/file-{A,B,C}.dat
and realize that you want to sort each file (numerically, let's suppose) before pasting. Then, using process substitution, you need to write something like this:
$ paste <(sort -n ../data/file-A.dat) \
<(sort -n ../data/file-B.dat) \
<(sort -n ../data/file-C.dat)
Here you see a lot of duplication, which is not a good thing. Because each process substitution is isolated from one another, you cannot use any brace expansion or pathname expansion (wildcards) that spans multiple process substitution.
Is there a tool that allows you to write this in a compact way (e.g. by giving sort -n
and ../data/file-{A,B,C}.dat
separately) and composes the entire command line for you?
eval
, but I see the arguments are securely handled above. The only concern I see is the handling of$cmd
: it will go through the usual expansions. This is fine whencmd
is fixed topaste
, but it can be problematic when you want to generalize this and acceptcmd
from the command line, as inlocal i n=1 cmd="$1"; shift; ...
. – musiphil Apr 23 '13 at 19:02