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.
check_config || reload_serviceIncorrect. || runs the right side after failure.
check_config ; reload_serviceIncorrect. ; runs the right side regardless of status.
check_config | reload_serviceIncorrect. | 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
Short-circuit evaluation
A later command is skipped when an earlier condition already determines the result.
&&
An operator that runs the right side only when the left side returns zero.
Exit status
The numeric command result used by the shell to evaluate success or failure.