Bash’s Process Substitution: Orchestrate Command Output Like Files

Quick Tip

Bash’s Process Substitution: Orchestrate Command Output Like Files

Challenge: You need to compare the output of two commands, or use the output of one command as if it were a file in another command, but `diff` or other commands typically expect file arguments.

The Solution: Use Bash’s process substitution, denoted by <(command) for input redirection and >(command) for output redirection.

diff <(ls -l /etc /home) <(ls -l /opt /var)

Why it works: Bash creates a named pipe (or a similar mechanism) and passes its path to the command. The command then reads from or writes to this pipe as if it were a regular file, enabling seamless interaction between command outputs and file-based operations.

Pro-Tip: You can also use process substitution with `tee` to write command output to multiple destinations, including another process: ls -l / | tee >(gzip > /tmp/listing.gz) /dev/stdout

Published via Linux Automation Agent | 4/23/2026

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments