I'm trying to create multiple process substitutions based on the output from the other command, however I'm not sure how I can achieve that.

As sample scenario, I've given list of files:

touch a.txt b.txt c.txt d.doc e.doc f.pdf g.pdf h.xls i.xls

I'm making the list of available file extensions:

ls -1 *.* | awk -F. '{if (NF>1) {print $NF}}' | sort | uniq

Then based on my dynamic list, I'd like to create the following FIFOs like:

pr -mt <(ls -1 *.doc) <(ls -1 *.pdf) <(ls -1 *.txt) <(ls -1 *.xls)

Which would allow me to print each set in different columns. However the above list of FIFOs is hardcoded so my goal is to find some way where I can substitute dynamic number of commands (like wildcard, using eval or xargs somehow).

Another scenario is described in here.

I'm not interested in specific solution (workaround) to above problem, as this is only one scenario. I'm interested how I can dynamically create process substitution in shell or what additional tools I can use to achieve that.

See also: How to create anonymous FIFO?

1 Answer 1


It's easy to dynamically build the string and eval it:

eval "$(echo -n 'pr -mt '; while read ext; do echo "<(ls -1 *.$ext)"; done < list  |tr '\n' ' ' )"

where list would be the file (possibly a fifo) representing the list of extensions you want to build the command from.

<() essentially creates unnamed FIFOs. An eval-less alternative might be to use named ones:

while read ext; do mkfifo ${ext}.pipe; ls -1 *.$ext > ${ext}.pipe & done
pr -mt *.pipe
rm *.pipe  #remove the named pipes when done

The above assumes you don't have other file names ending with ".pipe" in your directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.