Overwrite all.log with both standard output and standard error from run-job.
Use Bash redirection so both streams share the same opened destination.
Which command is correct?
Redirections are processed left to right. After > all.log opens FD 1 on the file, 2>&1 duplicates that destination for FD 2.
Detailed explanation
run-job 2> all.logIncorrect. It redirects only standard error; standard output remains on the terminal.
run-job > all.log 2>&1Correct. Standard output is opened on all.log first, then standard error is directed to the same destination.
run-job 2>&1 > all.logIncorrect. FD 2 is copied to the original terminal before FD 1 is redirected.
run-job > all.log 1>&2Incorrect. It sends standard output to standard error rather than opening both on all.log.
Try it yourself
An example you can run in a temporary verification environment.
bash -c 'printf OUT; printf ERR >&2' > /tmp/kp-all.log 2>&1; cat /tmp/kp-all.log; rm /tmp/kp-all.logExpected result
OUTERRKey points
- 2>&1 duplicates FD 1 for FD 2
- Redirections are evaluated left to right
- Both streams then share the file
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.