Stage 1 · Lesson 7 of 10
Writing Bash scripts
A is a shell script: a text file of commands the shell runs from top to bottom. It starts with a #!/usr/bin/env bash line and is made runnable with chmod +x. Learn variables, quoting, if tests, for loops, functions, (a number saying whether a command worked) and script arguments.
Start every script with set -euo pipefail. It stops the script at the first failed command, at an unset variable, or when any command inside a pipe fails. Quote your variables ("$file", not $file) so file names with spaces do not break things.
Run on everything you write; it catches common mistakes. Scripts automate backups, and deploy steps. The same shell lines later end up inside CI pipelines and .
Common trapletting a script grow to hundreds of lines; when it needs real data structures or error handling, rewrite it in Python.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CourseFreeThe Missing Semester of Your CS Education
MIT · Beginner
Shell, scripting, data wrangling, SSH and Git in a dozen focused lectures
- BookFreeThe Linux Command Line
William Shotts · Beginner
Free book: permissions, processes, packages and longer shell scripts, chapter by chapter