Interview Prep/Linux/Packages, Shell & Text Tools

What are exit codes and how do you check them?

BeginnerConceptPackages, Shell & Text Tools
Answer

Every command returns 0 for success and 1–255 for failure. $? holds the last one. Conventions: 1 general error, 2 misuse, 126 not executable, 127 command not found, 128+N killed by signal N (137 = SIGKILL, often OOM; 143 = SIGTERM).

grep -q ERROR app.log; echo $?
cmd || { echo "cmd failed" >&2; exit 1; }
All Linux questions Roadmap: Linux

More on Packages, Shell & Text Tools