Compare Command Output With Process Substitution

Feed the output of two commands directly into diff or other file readers.

macOSbashautomationshellscriptingLow risk
Run diff <(sort a.txt) <(sort b.txt) to compare the two sorted streams.

01Command

Command
$ diff <(sort a.txt) <(sort b.txt)

02What it does

Process substitution <(cmd) presents a command's output as a filename, so tools that only accept files can consume live command output. That avoids scratch files and keeps pipelines reproducible, which is a scripting advantage no GUI file compare offers.

03Risk

RiskLow risk
RequirementsmacOS default zsh/bash (bash 3.2+; some features need bash 4+ via Homebrew)
CompatibilitymacOS with bash 3.2+ (GNU bash 4+ via Homebrew for advanced features)
!Warning: Process substitution is a bash/zsh feature; POSIX sh needs a temporary file instead.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

Last verified: 2026-10-13 · Category: Developer