Process substitution

In computing, process substitution is a form of inter-process communication that allows the input or output of a command to appear as a file. The command is substituted in-line, where a file name would normally occur, by the command shell. This allows programs that normally only accept files to directly read from or write to another program.
History.
Process substitution was available as a compile-time option for codice_1, the 1988 version of the KornShell from Bell Labs. The rc shell provides the feature as "pipeline branching" in Version 10 Unix, released in 1990. The Bash shell provided process substitution no later than version 1.14, released in 1994.
Example.
The following examples use KornShell syntax.
The Unix diff command normally accepts the names of two files to compare, or one file name and standard input. Process substitution allows one to compare the output of two programs directly:
$ diff <(sort file1) <(sort file2)
The codice_2 expression tells the command interpreter to run "command" and make its output appear as a file. The "command" can be any arbitrarily complex shell command.
Without process substitution, the alternatives are:
Both alternatives are more cumbersome.
Process substitution can also be used to capture output that would normally go to a file, and redirect it to the input of a process. The Bash syntax for writing to a process is codice_3. Here is an example using the codice_4, codice_5 and codice_6 commands that counts the lines in a file with codice_7 and compresses it with codice_6 in one pass:
$ tee >(wc -l >&2) < bigfile | gzip > bigfile.gz
Advantages.
The main advantages of process substitution over its alternatives are:
Mechanism.
Under the hood, process substitution has two implementations. On systems which support codice_9 (most Unix-like systems) it works by calling the codice_10 system call, which returns a file descriptor codice_11 for a new anonymous pipe, then creating the string codice_12, and substitutes that on the command line. On systems without codice_9 support, it calls codice_14 with a new temporary filename to create a named pipe, and substitutes this filename on the command line. To illustrate the steps involved, consider the following simple command substitution on a system with codice_9 support:
$ diff file1 <(sort file2)
The steps the shell performs are:
For named pipes, the execution differs solely in the creation and deletion of the pipe; they are created with codice_14 (which is given a new temporary file name) and removed with codice_21. All other aspects remain the same.
Limitations.
The "files" created are not seekable, which means the process reading or writing to the file cannot perform random access; it must read or write once from start to finish. Programs that explicitly check the type of a file before opening it may refuse to work with process substitution, because the "file" resulting from process substitution is not a regular file.
Additionally, up to Bash 4.4 (released September 2016), it was not possible to obtain the exit code of a process substitution command from the shell that created the process substitution. 