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
- What is $? used for, and how do you check the exit status of a command? [Basic]
- What do set -e, set -u, set -o pipefail, and set -x do? [Basic]
- What is the difference between [ ], [[ ]], and (( )) in Bash? [Basic]
- What is command substitution, and what is the difference between $(...) and backticks? [Basic]
- What are the common file test operators (-f, -d, -e, -r, -w, -x)? [Basic]
- What is the difference between single quotes and double quotes in Bash? [Basic]
- What is the difference between $var and ${var}? [Basic]
- How do you declare a variable in Bash, and why are spaces around = not allowed? [Basic]