Save run-job's standard output to output.log.
Leave standard error on the original terminal and do not put it in the file. The order of FD duplication matters.
Which command satisfies the requirement?
In 2>&1 > output.log, FD 2 first duplicates the original FD 1. Later changing FD 1 does not retroactively change FD 2.
Detailed explanation
run-job > output.log 2>&1Incorrect. Both streams are sent to output.log.
Incorrect. Both streams are sent to output.log.
run-job 2> output.log 1>&2Incorrect. It sends both descriptors toward the same terminal/file relationship rather than preserving the original terminal for errors.
Incorrect. It sends both descriptors toward the same terminal/file relationship rather than preserving the original terminal for errors.
run-job 2>&1 > output.logCorrect. FD 2 keeps the original terminal while FD 1 is redirected to the file.
Correct. FD 2 keeps the original terminal while FD 1 is redirected to the file.
run-job > output.log 2> /dev/nullIncorrect. It discards standard error instead of leaving it on the terminal.
Incorrect. It discards standard error instead of leaving it on the terminal.
Try it yourself
An example you can run in a temporary verification environment.
bash -c 'printf OUT; printf ERR >&2' 2>&1 > /tmp/kp-only-out.log; printf '|'; cat /tmp/kp-only-out.log; rm /tmp/kp-only-out.logExpected result
ERR|OUTKey points
- Redirection order changes the result
- Duplication uses the destination at that moment
- A later FD 1 change does not affect FD 2
Notes
- Environment: Bash 5.2
- 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.