A required argument is missing, so processing cannot continue.
Return a status that lets the caller detect failure.
Which command is appropriate?
exit with a nonzero value terminates a script as a failure. The exact value should have a consistent documented meaning.
Detailed explanation
exit 0Incorrect. exit 0 reports success and would hide the argument error.
exit 2Correct. exit 2 returns a nonzero failure status.
continue 2Incorrect. continue controls loop iterations and does not terminate the script.
shift 2Incorrect. shift removes positional arguments and does not exit.
Try it yourself
An example you can run in a temporary verification environment.
sh -c 'exit 2'; printf '%s\n' "$?"Expected result
2Key points
- Nonzero means failure
- The caller receives the exit value
- Document meanings consistently
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
Shell function
A reusable group of commands that runs in the caller's shell context.
Positional parameter
A numbered argument or special value supplied to a script or function.
Control flow
Conditions, loops, and exit statuses determine which shell commands run.