Exit codes: $?, && and ||
cheat sheet · Ubuntu 24.04 · bash 5.2 https://lab.dimsanych.ru/en/wiki/exit-codes/Cheat sheet
-
ls /nope; echo $?2 — code of the last command -
grep -q root /etc/passwd && echo foundsecond runs after code 0 -
mkdir /srv/app || echo "failed" >&2second runs after non-zero -
if grep -q '^backup:' /etc/passwd; then echo found; fi -
rc=$?save the code before it's lost -
exit 1leave a script with code 1 -
false | true; echo "${PIPESTATUS[@]}"1 0 — code of every stage -
set -o pipefaila failed stage fails it all