$RodHat_/search
exit code reference

Exit 1

General failure: the catch-all.

Value
1
Convention
Shell and tool convention

There is no standard meaning beyond "something went wrong", which is why it is the most common failure value and the least useful. A few tools give it a specific, documented meaning: grep exits 1 when nothing matched (and 2 on a real error), so a script under set -e dies on a search that simply found nothing. Read the tool's own man page before treating 1 as an error.

What to check

grep -q pattern file; echo $?   # 0 match, 1 no match, 2 error

Sources

  1. Exit Status, GNU Bash manual
  2. Exit Status, GNU grep manual

Exit codes are conventions, not guarantees: a program can return any value from 0 to 255. Spot one that's wrong? Tell Rod.