`exit`/`return` takes only one argument
Extra arguments after `exit`/`return` are ignored, not concatenated or evaluated. SC2242 flags calls that pass more than one value.
Problem
`exit [n]` and `return [n]` take at most one argument, the numeric status code. If you pass additional words, Bash does not error — it simply ignores everything after the first argument, so code that tries to pass a message and a status together, like `exit "Error occurred" 1`, actually exits with the (non-numeric, so coerced) status from the first word and silently drops the rest. This is often the result of trying to combine an error message and an exit code in one statement, which the shell does not support directly.
Bad
if [ ! -f "$config" ]; then
exit "Config file not found" 1
fiGood
if [ ! -f "$config" ]; then
echo "Config file not found" >&2
exit 1
fiExplanation
Print any diagnostic message separately (typically to stderr with `>&2`) and then call `exit`/`return` with only the numeric status. This keeps the exit status meaningful for callers checking `$?` while still surfacing a human-readable message.
Related
SC2152
SC2181
SC2148
When It Matters
exit takes a single integer between 0 and 255. exit "$msg" or exit 1 "failed" is a syntax or range error, and in some shells it exits with a status you did not choose — frequently 0, which tells the caller that a failed script succeeded. Since CI systems and orchestrators branch on exit status, a wrong status is the difference between a pipeline that stops and one that ships broken output.
Second Example
Note
Status values above 125 collide with conventions used by the shell for signals and for "command not found", so keep custom codes in the 1..125 range.
Exceptions
None. If several failure modes need to be distinguished, define named status codes as constants at the top of the script and exit with those.
Faq
Q
What do exit statuses above 125 mean?
A
126 is "found but not executable", 127 is "command not found", and 128+n indicates termination by signal n. Avoid reusing them.
Q
What happens if I exit with a number above 255?
A
It is taken modulo 256, so exit 256 becomes 0 — a failure reported as success.
Q
Does return follow the same rules?
A
Yes, return takes one integer in the same range, and the same argument-count restriction applies.