Problem Statement
What does an exit status of 0 indicate?
Explanation
Exit status (return code) indicates whether command succeeded (0) or failed (non-zero). Access with $? immediately after command: command; echo $? shows exit status. By convention: 0 = success, 1-255 = various failure modes. Some commands use specific codes: grep returns 1 if no matches, 2 for errors.
Set exit status in scripts with exit N where N is 0-255. Exit 0 indicates success, exit 1 indicates general error. Not using exit allows script to return status of last command. Check status in conditionals: if command; then echo 'Success'; else echo 'Failed'; fi. The if statement checks whether command returns 0 (true) or non-zero (false).
Set -e makes script exit on any command failure (non-zero status), useful for safer scripts. Set -o pipefail makes pipelines return failure if any command fails (default returns status of last command). Understanding exit status enables proper error handling and conditional execution in scripts.
