Exit Codes
Every command that runs in Bash — not just the two built-ins true and false below — finishes with an exit status between 0 and 255. The special variable $? always holds the most recently finished command's exit status, and by convention 0 means success while any nonzero value means some kind of failure.
echo "exit code of true: $?" false echo "exit code of false: $?"
exit code of true: 0 exit code of false: 1
The first line's $? is checking echo's own previous command — true, which ran implicitly before the script's very first line finished — which is why it's already 0 before false even runs. This convention is the opposite of what a beginner usually expects from a boolean: 0 is "good", not "false".
Next: conditionals — if/then/else, and the single-bracket versus double-bracket test syntax.
Practice exercise
Run the true command and print its exit code using $?, then run the false command and print its exit code the same way.