Process substitution
How it works
Process substitution connects a running command to a filename-like endpoint rather than capturing its output as a string. <(command) lets another command read the producer output; >(command) lets another command write to a consumer input. Do not put a space between the angle bracket and opening parenthesis. Bash uses a pipe-related endpoint such as /dev/fd or a named pipe on supported systems. The process runs asynchronously; the outer command status is not automatically the producer status, and a consumer may finish later than the outer command. Do not save an endpoint for later use or assume it is a seekable regular file. This is not portable POSIX sh syntax. Examples use external cat (reads input or files) and diff (compares files).
Run each example separately in a noninteractive Bash 5.2 script in a fresh empty practice directory, with default options and C locale. Output is shown separately; do not enter it as code.
Read a generated stream
Expected stdout:
redbluecat reads the producer through a filename-like endpoint; trailing newlines survive.
Compare generated streams
diff <(printf 'ready\n') <(printf 'ready\n')printf 'status=%s\n' "$?"Expected stdout:
status=0diff reports no differences and exits with status zero.
Outer status is separate
cat <(printf 'partial\n'; false)printf 'status=%s\n' "$?"Expected stdout:
partialstatus=0cat reads the available bytes successfully despite the producer ending with false.
Common mistakes
Unlike $(...), process substitution provides access to a stream, not its text. A command that reads from it can succeed even if the producer fails. Output-side substitution and synchronization need more care; use the later pipeline and process chapters for reliable status handling.
Practice
Use diff with two input process substitutions producing ready followed by a newline. Predict its output and status; then change one producer to done and predict the status.
Next: Default values and unset versus null