Process substitution
In computing, process substitution is a form of inter-process communication that allows the input or output of a command to be made available as a file path.[src] The command is substituted in-line, where a file name would normally occur, by the command shell.[src] This allows programs that normally only accept file paths to directly read from or write to another program.[src]
In computing, process substitution is a form of inter-process communication that allows the input or output of a command to be made available as a file path.[src] The command is substituted in-line, where a file name would normally occur, by the command shell.[src] This allows programs that normally only accept file paths to directly read from or write to another program.[src] Zsh (since its first version in 1990), added a third form of process substitution ( =(cmd) ) that uses a temporary file instead of a pipe.[src] The fish shell added its own process substitution with yet another syntax in 2005, using pipes, then a variant using temporary files in 2007 which then became the default (initially inadvertently) as the pipe variant suffered from deadlocks.[src] $ diff The expression tells the command interpreter to run command and make its output appear as a file.[src] The command can be any arbitrarily complex shell code.[src] Without process substitution, the alternatives are: All of which are more cumbersome.[src] 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.[src] The KornShell syntax for writing to a process is >(command) .[src] Here is an example using the tee , wc and gzip commands that counts the lines in a file with wc -l and compresses it with gzip in one pass: $ tee >(wc -l >&2) bigfile.gz $ diff file1 The steps the shell performs are: Create a new anonymous pipe.[src] This pipe will be accessible with something like /dev/fd/63 ; you can see it with a command like echo .[src] Execute the substituted command in the background ( sort file2 in this case), piping its output to the anonymous pipe.[src] Simultaneously, execute the primary command, replacing the substituted command with a path to the anonymous pipe.[src] In this case, the full command might expand to something like diff file1 /dev/fd/63 .[src] When execution is finished, close the anonymous pipe.[src] For named pipes, the execution differs solely in the creation and deletion of the pipe; they are created with mkfifo() (which is given a new temporary file name) and removed with unlink() .[src] All other aspects remain the same.[src] The variants using temporary files such as Zsh's cmd1 =(cmd2) or Fish's cmd1 (cmd2|psub -f) first run with its output redirected to a temporary file, then run with substituted with the path of that temporary file and automatically delete that file after terminates.[src]
22 sentences · 22 cited inline · 0 references stored
References
No reference rows published for this article.
Cite this article
MLA
"Process substitution." encyclopegia.org, 2026, https://encyclopegia.org/wiki/process-substitution. Accessed 27 November 2026.
Chicago
"Process substitution." encyclopegia.org. Accessed November 27, 2026. https://encyclopegia.org/wiki/process-substitution.
APA
encyclopegia.org. (2026). Process substitution. Retrieved November 27, 2026, from https://encyclopegia.org/wiki/process-substitution
Accessed November 27, 2026 · CC BY-SA 4.0 · citation page · JSON