One liner for setting exit code to numbers under your control

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the bash category.

Last Updated: 2024-03-29

I wanted to write a health check script that always returned a predictable exit code (the number 1) if a HTTP service was down. This predictability was to replace getting (e.g.) 10 possible exit codes depending on the exact reason the curl command failed.

The code ended up as the following

curl --fail localhost:8000 || exit 1

How does this work?