[prev] [index] [next]

Exit Status and Control

Process exit status is used for control in shell scripts:
  • zero exit status means command successful true
  • non-zero exit status means error occurred false
Mostly, exit status is simply ignored   (e.g. when interactive)

One application of exit statuses:

  • AND lists    cmd1 && cmd2 && ... && cmdn
    (cmdi+1 is executed only if cmdi succeeds (zero exit status))
  • OR lists    cmd1 || cmd2 || ... || cmdn
    (cmdi+1 is executed only if cmdi fails (non-zero exit status))