Run build_cache only if load_cache fails.
Which form is appropriate?
command1 || command2 runs command2 only when command1 returns a nonzero status. It is useful for fallback actions.
Detailed explanation
load_cache && build_cacheIncorrect. && runs build_cache after success.
Incorrect. && runs build_cache after success.
load_cache || build_cacheCorrect. build_cache runs only when load_cache fails.
Correct. build_cache runs only when load_cache fails.
load_cache ; build_cacheIncorrect. ; runs build_cache regardless of the result.
Incorrect. ; runs build_cache regardless of the result.
load_cache | build_cacheIncorrect. | connects standard input and output rather than testing status.
Incorrect. | connects standard input and output rather than testing status.
Try it yourself
An example you can run in a temporary verification environment.
sh -c 'false || echo fallback; true || echo skipped'Expected result
fallbackだけを表示Key points
- || continues after failure
- Nonzero means failure
- It is used for fallback processing
Notes
- Environment: POSIX sh / 状態変更なし
- 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.