Check Each Bash Pipeline Stage Before Calling a Logged Command Successful
A support recipe may pipe a diagnostic command through another program to filter or save its output. The final program can finish successfully even when the diagnostic itself failed. Keep the result of the actual operation separate from the result of displaying or recording it.
Learn the distinction with a harmless example
In Bash, consider false | true. The first command deliberately returns failure and the second returns success. With the usual pipeline behaviour, the pipeline's reported status comes from the last command, so that overall status can be zero.
Bash's PIPESTATUS array holds the statuses of the most recent foreground pipeline's commands. Immediately after the example, echo "${PIPESTATUS[@]}" displays the component results. Capture them before running another command: even a simple command replaces the current status information.
This is a Bash-specific check. Do not assume another shell exposes the same array or that a command copied into an application's console is being interpreted by Bash.
Apply the check to the real evidence
For an approved diagnostic pipeline, label each stage by its purpose: collecting information, filtering it, or writing a log. Preserve the observed component results with the command and its output. A successful log-writing stage does not demonstrate that the collection stage obtained the requested information.
Bash's pipefail option changes the overall result to the rightmost nonzero stage result, or zero when all stages succeed. It can be useful in a deliberately designed script, but it does not replace identifying which stage failed. Do not add it globally to an unfamiliar maintenance script without reviewing how that script handles errors.
Interpret each program's status using its own documentation. Some tools use distinct nonzero values for a normal no-match result and an actual error. Keep that meaning alongside the raw number.
Before rerunning a pipeline with side effects, check whether any earlier stage already completed its work. The acceptance record should identify the intended result and the relevant stage outcomes, rather than relying on one green exit code from the final formatting command.
Sources: GNU documentation, GNU documentation.