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
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 the purpose of the shebang line, and what does #!/bin/bash do? [Basic]
- What is the difference between sh and bash? [Basic]
- How do you make a script executable and run it? [Basic]
- What is the difference between running a script with ./script.sh, bash script.sh, and source script.sh? [Basic]
- What does sourcing a script do differently from executing it? [Basic]
- How do you declare a variable in Bash, and why are spaces around = not allowed? [Basic]
- What is the difference between $var and ${var}? [Basic]
- What is the difference between single quotes and double quotes in Bash? [Basic]