Append check-service's standard output to the end of history.log.
Keep the records already in history.log.
Which command is appropriate?
The >> operator appends standard output to an existing file. If the file does not exist, it is normally created.
Detailed explanation
check-service > history.logIncorrect. > truncates history.log before writing.
Incorrect. > truncates history.log before writing.
check-service >> history.logCorrect. >> preserves existing records and adds the new output at the end.
Correct. >> preserves existing records and adds the new output at the end.
check-service 2>> history.logIncorrect. 2>> appends standard error, not standard output.
Incorrect. 2>> appends standard error, not standard output.
history.log >> check-serviceIncorrect. The operands are not a command and a valid output redirection in this form.
Incorrect. The operands are not a command and a valid output redirection in this form.
Try it yourself
An example you can run in a temporary verification environment.
printf 'first
' > /tmp/kp-history.log; printf 'second
' >> /tmp/kp-history.log; cat /tmp/kp-history.log; rm /tmp/kp-history.logExpected result
first
secondKey points
- >> appends
- Existing content is preserved
- A missing destination is created
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.