Run: run-check 2>&1 > output.log
Determine where each stream normally goes.
Which result is appropriate?
2>&1 copies the current stdout connection first; the later > output.log changes stdout only, leaving stderr on the original terminal.
Detailed explanation
Incorrect. stderr was copied before stdout moved to output.log.
Incorrect. stderr was copied before stdout moved to output.log.
Correct. stdout goes to output.log while stderr retains the original terminal connection.
Correct. stdout goes to output.log while stderr retains the original terminal connection.
Incorrect. The command does not use 2> output.log.
Incorrect. The command does not use 2> output.log.
Incorrect. Neither stream is connected to /dev/null.
Incorrect. Neither stream is connected to /dev/null.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp); captured=$(sh -c 'echo out; echo err >&2' 2>&1 >"$tmp"); printf 'terminal=%s file=%s\n' "$captured" "$(cat "$tmp")"; rm -f "$tmp"Expected result
terminal=err file=outKey points
- 2>&1 copies the current connection
- A later > changes stdout only
- Order changes the result
Notes
- Environment: POSIX shell / 一時ファイルとcommand substitution
- 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.