Run notify_failure only when backup exits nonzero.
Which command list is appropriate?
The || list runs the right command only when the left command fails.
Detailed explanation
backup && notify_failureIncorrect. && runs the notification after success.
Incorrect. && runs the notification after success.
backup ; notify_failureIncorrect. ; runs the notification in both success and failure cases.
Incorrect. ; runs the notification in both success and failure cases.
backup & notify_failureIncorrect. & starts backup asynchronously without checking its result.
Incorrect. & starts backup asynchronously without checking its result.
backup || notify_failureCorrect. notify_failure runs only when backup returns nonzero.
Correct. notify_failure runs only when backup returns nonzero.
Try it yourself
An example you can run in a temporary verification environment.
false || printf notified; true || printf not-runExpected result
notifiedだけを表示Key points
- || on nonzero
- Short-circuit evaluation
- Success skips the right side
Notes
- Environment: GNU Bash 5.2 / Bash組込みtrue・false
- 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.