Error Detection
Detect if a command ran successfully.
Shell Script · Exit Status
Shell Scripting · Lesson 17
Understand exit status in Linux commands. Use $? in scripts. Error handling technique. Build reliable automation scripts.
Every command executed in Linux returns an exit status. It is a numeric value that tells whether a command succeeded or failed.
By convention:
Detect if a command ran successfully.
Control script execution based on success or failure.
Helps identify which command failed.
Every command returns an exit status after execution.
0 means success, non-zero means failure.
Use $? to check if a command succeeded.
Use exit to define your own exit status.
Next lesson: Debugging & Traps