Save build stdout to build.out and stderr to build.err, overwriting both files.
Which command is appropriate?
> build.out connects stdout and 2> build.err connects stderr to different destinations.
Detailed explanation
build > build.out 2>&1Incorrect. Both streams are combined into build.out.
build 2> build.out > build.errIncorrect. The requested stdout and stderr destinations are reversed.
build > build.out 2> build.errCorrect. build > build.out 2> build.err assigns separate files.
build < build.out 2< build.errIncorrect. These redirections attempt to use the files as input.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp -d); sh -c 'echo out; echo err >&2' >"$tmp/o" 2>"$tmp/e"; printf '%s/%s\n' "$(cat "$tmp/o")" "$(cat "$tmp/e")"; rm -rf "$tmp"Expected result
out/errKey points
- 1> is stdout
- 2> is stderr
- Streams can be separated
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
Keeping streams separate makes normal results and diagnostics independently reviewable.
Check the side effect
Use temporary files and confirm each receives only its intended stream.