Overwrite errors.log with validate-config's standard error.
Keep standard output displayed on the terminal.
Which command is appropriate?
2> redirects file descriptor 2, standard error. File descriptor 1, standard output, remains connected to the terminal.
Detailed explanation
validate-config > errors.logIncorrect. > redirects standard output, not standard error.
Incorrect. > redirects standard output, not standard error.
validate-config >> errors.logIncorrect. >> appends standard output and still leaves standard error on the terminal.
Incorrect. >> appends standard output and still leaves standard error on the terminal.
validate-config < errors.logIncorrect. < redirects input from errors.log.
Incorrect. < redirects input from errors.log.
validate-config 2> errors.logCorrect. 2> captures only standard error in errors.log.
Correct. 2> captures only standard error in errors.log.
Try it yourself
An example you can run in a temporary verification environment.
bash -c 'printf OUT; printf ERR >&2' 2> /tmp/kp-errors.log; printf '|'; cat /tmp/kp-errors.log; rm /tmp/kp-errors.logExpected result
OUT|ERRKey points
- FD 2 is standard error
- FD 1 is standard output
- 2> overwrites the error 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.