Run reload_service only when check_config exits successfully.
Which form is appropriate?
command1 && command2 runs command2 only when command1 returns exit status 0.
Detailed explanation
check_config && reload_serviceCorrect. The right side runs only when check_config succeeds.
Correct. The right side runs only when check_config succeeds.
check_config || reload_serviceIncorrect. || runs the right side after failure.
Incorrect. || runs the right side after failure.
check_config ; reload_serviceIncorrect. ; runs the right side regardless of status.
Incorrect. ; runs the right side regardless of status.
check_config | reload_serviceIncorrect. | creates a pipeline, not a success condition.
Incorrect. | creates a pipeline, not a success condition.
Try it yourself
An example you can run in a temporary verification environment.
sh -c 'true && echo ran; false && echo skipped; :'Expected result
ranだけを表示Key points
- && continues after success
- Exit status 0 means success
- It uses short-circuit evaluation
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.