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
- 01Exit codes
- 02A first script
- 03Make it safe
- 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.