Pebellslearn by building
RoadmapsMatrixCoursesSandboxSign in

Course details

Shell / Bash

Learn to write Bash scripts that are safe, readable and reusable. You will grow one small backup script from three typed commands into a tool with arguments, checks, loops and functions, learning why every quote and bracket is there.

Ready to learn6 sections · 24 lessons
Start learning

Course curriculum

Your First Bash Script3 lessons

What Bash is, why scripting beats retyping, how a script file is laid out, and the three ways to run one. You start backup.sh, the script this whole course grows.

  1. What Bash Is, and Why Script It10 min
  2. Anatomy of a Script: Shebang and Comments12 min
  3. Three Ways to Run a Script12 min
Variables and Data4 lessons

Create and change variables, learn the quoting rules that stop spaces from breaking your script, do whole-number arithmetic, and keep lists in arrays. backup.sh stops hard-coding its paths.

  1. Variables: Create, Read, Change12 min
  2. Quoting: Double, Single, None14 min
  3. Numbers and Arithmetic Expansion12 min
  4. Arrays and Associative Arrays14 min
Input and Output4 lessons

Read answers from the user, format output with printf, write multi-line text with here documents and here strings, and capture a command's output with command substitution. backup.sh learns to ask, report and stamp its archives with the date.

  1. Reading Input with read12 min
  2. printf for Tidy Output12 min
  3. Here Documents and Here Strings12 min
  4. Command Substitution: Capture Output12 min
Arguments and String Manipulation4 lessons

Read positional arguments, pass every argument on safely with "$@", step through them with shift, and cut, trim and replace text with parameter expansion. backup.sh starts taking its folder from the command line.

  1. Positional Arguments: $0, $1 and $#12 min
  2. "$@", $* and shift14 min
  3. String Length and Substrings12 min
  4. Trimming, Replacing and Changing Case14 min
Exit Codes and Conditionals4 lessons

Read and set exit codes, branch with if and the [[ ]] test, chain commands with && and ||, and match patterns with case. backup.sh learns to refuse bad input and stop when something fails.

  1. Exit Codes: $? and exit12 min
  2. if and the [[ ]] Test15 min
  3. &&, || and ! : Chaining on Success12 min
  4. case: Matching Patterns14 min
Loops and Functions5 lessons

Walk lists with for, repeat on a condition with while and until, steer loops with break and continue, then organise the script into functions with local variables. backup.sh becomes a small, well-structured tool.

  1. for Loops: Once per Item12 min
  2. while and until Loops14 min
  3. break and continue10 min
  4. Functions: Named Steps14 min
  5. local, Scope and the Finished Script15 min