The Warnet Desa’s night script: each job runs in a model bash with its real status, a green lamp for 0. && only on success, || on failure, ; always; plus set…
Why it matters
CI green while the build failed, a deploy that runs after the tests failed, a script that stops halfway without a word: all about exit statuses. 0 means success (the opposite of false in many languages), and $? keeps only the last one.
The key idea
0 is success, and $? is only the last one
Common mistakes
My script exit 0s, I thought that meant failure In the shell 0 means success, the opposite of false/0 in JavaScript or Python. Anything but 0 means failure.
My && chain stops halfway with no error message Some command had a non-zero status but printed nothing (a grep that found nothing). Check each step’s $?, or echo $? after it.
My CI is green though the build failed CI looks at the last status only. build; echo done is always 0. Use &&, set -e, and set -o pipefail for pipes.
I have set -e but the script goes on after a command failsset -e does not apply to a command followed by && or || (or inside an if). Put the command on its own, or add || exit 1.
Try it in this playground
See && skip a job The job before fails, and the next lamp stays dark.
Rescue with || cd dist fails, then || runs mkdir dist.
Get a 127 Mistype a command’s name: ehco done.
Catch a failure inside a pipe Turn pipefail on for cat missing.txt | wc -l.