Save both run-check standard output and standard error to all.log, replacing the file.
Use POSIX-style file-descriptor duplication.
Which order is appropriate?
Redirections are processed left to right. Redirect stdout first, then duplicate that file connection onto stderr with 2>&1.
Detailed explanation
run-check > all.log 2>&1Correct. stdout is opened on all.log first, then stderr is duplicated to the same destination.
run-check 2>&1 > all.logIncorrect. stderr is copied to the original stdout before stdout is redirected, so it stays on the terminal.
run-check > all.log 1>&2Incorrect. The final 1>&2 changes stdout to stderr rather than retaining both on the file.
run-check 2> all.log > /dev/nullIncorrect. stdout is sent to /dev/null and is not saved in all.log.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp); sh -c 'echo out; echo err >&2' >"$tmp" 2>&1; sort "$tmp"; rm -f "$tmp"Expected result
err
outKey points
- Redirections are left to right
- 2>&1 duplicates fd 1
- Both streams share the file
Notes
- Environment: POSIX shell / 一時ファイル
- Use temporary files and harmless commands for stream experiments.
- Shell redirection syntax and xargs behavior should be checked on the target shell implementation.
Foundation review
Place the operation
A descriptor duplication must occur after the destination for standard output has been selected when both should share it.
Check the side effect
Test with a command that emits one message on each stream and inspect the combined file.