Bash / Shell Scripting
Write reliable Bash scripts: quoting, expansions, tests and loops, functions and arrays, redirection and pipes, strict mode, traps, ShellCheck and cron.
What you'll learn
- Explain what Bash is, how it relates to sh, dash and zsh, and how scripts are run and exit.
- Use variables, quoting and parameter expansion correctly to avoid word-splitting and globbing bugs.
- Write conditions, loops, functions and arrays, and parse command-line options with getopts.
- Redirect streams, build safe pipelines and process text and JSON with grep, sed, awk and jq.
- Make scripts robust with strict mode, traps, temporary files, locking, atomic writes and ShellCheck.
- Automate tasks with background jobs, cron and systemd timers, and know when to switch to another language.
Syllabus
Shells and Your First Script
- What Bash Is
- Shebang, Permissions, PATH and Exit Codes
- Builtins, External Commands, Aliases and Functions
Variables, Quoting and Expansion
- Variables and the Environment
- Quoting, Word Splitting and Globbing
- Parameter Expansion, Command Substitution and Arithmetic
Conditions and Loops
- Tests: [[ ]], [ ] and (( ))
- if, elif, case and Short-Circuit Operators
- for, while and Reading Lines Safely
Functions, Arrays and Arguments
Input, Output and Text Processing
- Redirection and Here-Documents
- Pipelines, pipefail, Process Substitution and xargs
- Text Processing with grep, sed, awk and jq
Writing Robust Scripts
- Strict Mode: set -euo pipefail and Its Caveats
- Traps, Cleanup and Temporary Files
- Debugging, ShellCheck and Formatting