Write Your First Bash Scripts

Start from an empty file and end with two small commands of your own: one that counts matching lines in a log and one that turns that count into an alert, with arguments, tests, error messages and exit codes done properly.

Skill labbeginner~30 minFree

What you'll do

  • ✓Read and set exit statuses, and know what 0 means
  • ✓Create a script with a shebang and the execute bit that takes positional arguments
  • ✓Check the number of arguments and a file with test, and report errors on standard error
  • ✓Quote variables so that spaces do not break the script
  • ✓Use one script from another with command substitution and if

Lab outline

  1. 01Exit codes
  2. 02A first script
  3. 03Make it safe
  4. 04Build on it

Before you start

  • Shell Environment and a Repeatable Inventory
  • Search Logs and Build Pipelines

Every lab runs on a real machine of your own in the browser — no installs, nothing to clean up — and checks your work automatically as you go.

← All Linux System Administration labs

Your first machine is
8 seconds away.

Learn by doing on real machines — and give every AI agent one of its own.

Free forever · No credit card · Cancel anytime

Write Your First Bash Scripts — Linux lab | Kube Labs