Overwrite errors.log with validate standard error.
Leave standard output connected to the terminal.
Which redirection is appropriate?
2> FILE redirects file descriptor 2, standard error, while standard output remains connected as before.
Detailed explanation
validate > errors.logIncorrect. > saves stdout and leaves stderr on the terminal.
Incorrect. > saves stdout and leaves stderr on the terminal.
validate >> errors.logIncorrect. >> appends stdout rather than capturing stderr.
Incorrect. >> appends stdout rather than capturing stderr.
validate < errors.logIncorrect. < supplies errors.log as standard input.
Incorrect. < supplies errors.log as standard input.
validate 2> errors.logCorrect. 2> errors.log redirects only standard error.
Correct. 2> errors.log redirects only standard error.
Try it yourself
An example you can run in a temporary verification environment.
tmp=$(mktemp); sh -c 'printf out; printf err >&2' 2>"$tmp"; printf ' file='; cat "$tmp"; rm -f "$tmp"Expected result
端末側にout file=errKey points
- File descriptor 2 is stderr
- 2> overwrites
- stdout is a separate stream
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.