Process and descriptor topology
A pipeline connects a producer's stdout to the next component's stdin before explicit redirections on the producer are applied. A later > file can replace that pipe connection, so the consumer reads EOF once all write ends close. With |&, Bash duplicates stderr onto stdout after the explicit producer redirections. File descriptors are handles, not filenames: duplication shares an open file description (including offset for a regular file), whereas opening a path again may establish a separate open description. A subshell normally has its own variable state and inherited descriptors; BASHPID identifies the current Bash process while $$ can retain the original shell PID. BASH_SUBSHELL reports subshell environment nesting, not an operating-system process count. Pipeline children normally execute in separate processes, with lastpipe as a documented exception for the final component. EOF requires all pipe write ends to be closed; leaked inherited handles can delay it. For terminals, process groups and controlling terminals matter; do not infer foreground groups from a shell variable. Use controlled descriptors and bounded workers; avoid claiming a fixed internal fork or syscall sequence.
Conceptual descriptor diagram (not a syscall trace):
producer fd 1 -> pipe -> consumer fd 0producer fd 1 -> saved.txt (after > saved.txt) pipe -> consumer fd 0 (EOF after writers close)``` Use pipefail and check the pipeline before inspecting the output file. In the descriptor example, verify the open and both reads before displaying their values.Practical examples
Run each example as a separate script in a fresh noninteractive Bash 5.2 process and empty practice directory. Tests use C locale; do not enter expected output as code.
Redirect a producer away from the pipe
set -o pipefailprintf 'payload\n' > saved.txt | wc -c || exit 1cat saved.txtExpected stdout:
0payloadThe explicit output redirection replaces the producer pipe connection.
Observe shared descriptor offset
printf 'first\nsecond\n' > input.txt || exit 1exec 3< input.txt || exit 1exec 4<&3 || exit 1IFS= read -r -u 3 first || exit 1IFS= read -r -u 4 second || exit 1printf '%s/%s\n' "$first" "$second"exec 4<&- 3<&- || exit 1Expected stdout:
first/secondThe duplicate descriptor shares the open file offset; the second read continues from the first.
Observe subshell identity without fixed PIDs
parent=$BASHPIDoriginal=$$( [[ $BASHPID != "$parent" ]] && printf 'different-process\n' [[ $$ == "$original" ]] && printf 'same-dollar-dollar\n' (( BASH_SUBSHELL > 0 )) && printf 'nested\n' )Expected stdout:
different-processsame-dollar-dollarnestedAssertions compare identities, not machine-dependent numeric PIDs.
Common mistakes
Do not assume pipes override all explicit redirects or that subshell depth equals process count. Close only descriptors you own.
Practice
Draw descriptor 1 for a producer before and after > file in a pipeline. Verify both the file and downstream byte count. Explain which writes must end before EOF.
Next: Bash internals and implementation boundaries