Process substitution in Bash
A command's output, standing in for a file.
# <( ) lets a command's output stand in for a file
diff <(printf 'a\nb\nc\n') <(printf 'a\nx\nc\n') || true
# comm wants sorted files; process substitution sorts on the fly
comm -12 <(printf 'b\na\n' | sort) <(printf 'c\nb\n' | sort)
# tee splits a stream: one copy on, one copy saved
tmp=$(mktemp)
seq 1 3 | tee "$tmp" | wc -l
rm "$tmp"
How it works
<( )gives commands likediffa file-shaped stream.commgets its sorted inputs made to order.teecopies a stream to a file while it keeps flowing.
Keywords and builtins used here
printftrue
The run, in numbers
- Lines
- 10
- Characters to type
- 339
- Tokens
- 52
- Three-star pace
- 75 tpm
At the three-star pace of 75 tokens a minute, this run takes about 42 seconds.
Step 3 of 3 in Pipes & redirection, step 18 of 26 in Language basics.