Linux Labs

Bash: text processing and scripts / Stage 7 of 9

Exit status and a healthcheck

Not running Starting usually ~20 s
Leave the lesson

Step 8 of 8 · summary · 2 min

Summary

  • An exit status is the number a command reports its result with: 0 is success, anything else a failure. $? holds it until the next command.
  • if, && and || look at a command's status directly, and a script hands over its own status with exit — timers and monitoring read it.
  • curl succeeds on any answer it receives: -f turns an answer with status 400 or above into a failure, and --max-time cuts off a hang.
  • set -euo pipefail stops a script on an unchecked failure, a typo in a variable and a failure inside a pipeline.
  • healthcheck.sh from the start of the lesson printed OK because the condition checked the status of the echo that stood between curl and if.
Ubuntu 24.04
Loading…