Pass both run-check stdout and stderr to grep and select lines containing FAIL.
Use POSIX syntax.
Which command sequence is appropriate?
Redirect stderr to stdout on the left command, then pipe the combined stream to grep.
Detailed explanation
run-check | grep FAILIncorrect. Only stdout enters the pipe; stderr stays on the terminal.
Incorrect. Only stdout enters the pipe; stderr stays on the terminal.
run-check 2>&1 | grep FAILCorrect. 2>&1 merges both streams before the pipe sends them to grep.
Correct. 2>&1 merges both streams before the pipe sends them to grep.
run-check 2> grep FAILIncorrect. This redirects stderr to a file named grep rather than piping it.
Incorrect. This redirects stderr to a file named grep rather than piping it.
run-check | grep FAIL 2>&1Incorrect. It redirects grep's own stderr and does not pipe run-check stderr.
Incorrect. It redirects grep's own stderr and does not pipe run-check stderr.
Try it yourself
An example you can run in a temporary verification environment.
sh -c 'echo OK; echo FAIL-error >&2' 2>&1 | grep FAILExpected result
FAIL-errorKey points
- A pipe normally carries stdout only
- 2>&1 merges stderr
- Merge on the left command
Notes
- Environment: POSIX shell / grep / 生成出力
- Command output formatting can vary slightly by distribution or tool version.
- Run the example in a temporary directory or process when possible.
Foundation review
Read the scope first
Check whether the command acts on the current shell, a new process, an existing process, or a file.
Verify the observable result
Use the supplied command and compare the output with the expected result.