Interview Scripting (Bash, Groovy)

What does an exit code of 0 versus non-zero mean? [Basic]

Answer

By convention, exit code 0 means success and a nonzero exit code means failure. Automation tools, CI jobs, cron, systemd, and pipelines use this status to decide whether a step succeeded.

Technical explanation

Exit codes are limited to 0-255 in the shell; choose small meaningful values and document them for complex scripts.

Different tools may use specific nonzero codes, so preserve the original code when wrapping commands unless you intentionally normalize it.

A script should exit nonzero when it fails so upstream automation does not treat a broken run as successful.

Hands-on example

validate_config() { [[ -f config.yaml ]] || return 10 yq e . config.yaml >/dev/null || return 11}

validate_config || exit $?echo "config is valid

Preparing for an interview?

Check how well your resume matches the role with our free resume checker— match score, ATS check, and the skills you're missing.

More Scripting (Bash, Groovy) interview questions

← All Scripting (Bash, Groovy) questions