All required processing has finished.
Return success to the caller and terminate the script.
Which command is appropriate?
exit 0 terminates the current script with status 0, which callers conventionally interpret as success.
Detailed explanation
exit 0Correct. exit 0 returns success and ends the script.
Correct. exit 0 returns success and ends the script.
exit 1Incorrect. A nonzero value generally signals failure.
Incorrect. A nonzero value generally signals failure.
return 0Incorrect. return is for functions or sourced files; top-level scripts use exit.
Incorrect. return is for functions or sourced files; top-level scripts use exit.
break 0Incorrect. break exits a loop, not the script with a selected status.
Incorrect. break exits a loop, not the script with a selected status.
Try it yourself
An example you can run in a temporary verification environment.
sh -c 'exit 0'; printf '%s\n' "$?"Expected result
0Key points
- 0 means success
- exit terminates the script
- The caller can test the status
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.