Two forms, one idea
Bash has two forms of process substitution. The form <(command) runs the command in the background, with its standard output connected to a pipe, and substitutes a path that names the read end of that pipe. The form >(command) does the reverse: it substitutes a path that names the write end, so anything written to that path flows into the command. The inner command runs in its own process, and the outer command simply sees a file.
The substituted path is typically under /dev/fd, which is a directory of links to the open descriptors of the current process. The exact number is not important, and you should never rely on it.
echo <(true)The output is a path such as /dev/fd/63. The number changes from one run to the next, because it is simply the descriptor bash opened for the pipe. The true command has already exited, but the path stays valid for the reader.
Comparing two outputs
A classic use is to compare the output of two commands with diff. The diff utility wants file names, and process substitution provides them without any files on disk. Each side is produced by its own command, and diff reads both as ordinary files.
diff <(printf 'a\nb\n') <(printf 'a\nc\n')The output shows the change that turns the first stream into the second: line b is replaced by c. Without process substitution you would need two temporary files, plus cleanup code to remove them afterward.
Reading into a loop without a subshell
Earlier you saw that a loop at the end of a pipeline runs in a subshell, so variables set inside it are lost. Process substitution fixes this, because the loop reads from a file path and runs in the current shell.
count=0
while read -r x; do count=$((count+1)); done < <(printf 'a\nb\n')
echo "count=$count"The output is count=2. The loop was not in a pipeline, so its changes to count stayed in the shell that printed the result. The redirection from the process substitution provided the input.
When a loop must update variables, prefer done < <(command) over command | while ...; done. The first keeps the loop in the current shell.
Writing into a command
The form >(command) is less common but just as useful. It lets one command write into another that is expecting a file name. The example below sends a stream to a counter while also printing it, using tee to copy the data.
printf 'x\ny\n' | tee >(wc -l > count.txt) > /dev/null
cat count.txtThe file count.txt contains 2. The tee copy went into the process substitution, and wc wrote its result to a file. The shell waits for the inner command, but it is not guaranteed to wait before the next command starts, so scripts that depend on the file should wait for it explicitly.
Combining several sources into one stream
A process substitution can stand wherever a file name is expected, so a command can read several generated streams at once. The example concatenates two small generated lists and counts the lines, without writing either list to disk.
cat <(printf 'a\nb\n') <(printf 'c\n') | wc -lThe count is 3. The two producers ran concurrently, and cat read them in the order they appeared on its command line, so the output keeps the argument order even though the processes run at the same time.
Limits and portability
Process substitution is a bash feature, and it is not part of the POSIX shell language. Scripts that must run under sh on minimal systems should use named pipes or temporary files instead. Inside bash it is safe, and it does not require any extra permissions.
Another limit is that the substituted path is a pipe, not a regular file. Programs that seek, check the file size, or reopen it by name may misbehave. Most tools that read a file sequentially work well with it, but a tool that needs random access does not.
Hands-on: sort two lists and compare
Use process substitution to sort two lists on the fly and find the lines that appear only in the first. The comm utility compares two sorted streams, so the inputs are sorted inside the substitutions.
comm -23 <(printf 'b\na\nc\n' | sort) <(printf 'c\n' | sort)The output is a and b, the lines that appear in the first list but not in the second. Each list was sorted in its own process, and comm read both as files. This is a compact replacement for a multi-step script with temporary files.