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.
Incorrect. Both streams are combined into build.out.
build 2> build.out > build.errIncorrect. The requested stdout and stderr destinations are reversed.
Incorrect. The requested stdout and stderr destinations are reversed.
build > build.out 2> build.errCorrect. build > build.out 2> build.err assigns separate files.
Correct. build > build.out 2> build.err assigns separate files.
build < build.out 2< build.errIncorrect. These redirections attempt to use the files as input.
Incorrect. 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 / 一時ディレクトリ
- 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.