bash process substitution

Updated: 11 January 2023


Process substitution feeds the output of a process (or processes) into the stdin of another process. It uses /dev/fd/<n> files to send the results of the process(es) within parentheses to another process. Effectively, process substitution turns a command into a temporary file, which is removed when the command completes.

cat <(echo hello world) # hello world
echo <(echo hello world) # /dev/fd/63

The first command converts the output of echo hello world into a file with contents hello world. The second command shows us the temp file in use.

The diff command requires files as arguments. So, comparing the contents of two directories can be achieved with diff and process substitution

diff <(ls /bin) <(ls /usr/bin)