StackMonsters

Course · 02

Bash Scripting

Write bash scripts on a Linux machine that runs in your browser. Start with commands in a file, then quote safely, make decisions, loop, write functions, make scripts safe, and turn logs into answers. Every lab is graded by running your script. Nothing to install.

7
chapters
42
lessons & labs
Chapter 1
free, no account needed
After Linux
builds on Linux Essentials

Who it's for

People who know the shell and are tired of typing the same lines.

  • Anyone who finished Linux Essentials and types the same commands every day
  • Sysadmins and support engineers who want their checks to run on their own
  • Developers who need to read and fix the scripts in a project

What you'll be able to do

Write the scripts a team runs every day, and trust them at 3 AM.

  • Write scripts that take arguments, check their input and fail clearly
  • Use exit codes, if, case and loops to react to what happens
  • Organise scripts into functions and libraries
  • Make scripts safe with quoting, set -euo pipefail, trap and ShellCheck
  • Turn logs into answers with grep, cut, sort, awk and sed

The path

7 chapters, from your first script to safe scripts that turn logs into answers.

Each lesson is short and ends in a quiz, then a lab on a simulated Ubuntu machine in your browser, graded by running your script. Each chapter ends in a timed challenge. Chapter 1 is free.

  1. 01

    Your First Scripts

    Put commands in a file, give it input, and let it decide

    Free
    1. 1Your Morning ScriptLab6 min
    2. 2Make It Run Like a ProgramLab6 min
    3. 3Open the ShopLab6 min
    4. 4Numbers into VariablesLab6 min
    5. 5One Script, Many QuestionsLab7 min
    6. 6Count Every LogLab7 min
    7. 7Count the Logs, SafelyLab7 min
    8. 8Challenge: The Nightly BackupLab10 min
  2. 02

    Quotes and Values

    Know what bash does to a line before it runs

    1. 1Quotes and Word Splitting5 min
    2. 2The Order That Didn't CopyLab4 min
    3. 3Count Any LevelLab6 min
    4. 4Change a Value with ${…}Lab6 min
    5. 5Loaves BakedLab5 min
    6. 6Challenge: The Messy UploadsLab15 min
  3. 03

    Decisions

    React to success and failure

    1. 1Exit Codes5 min
    2. 2Did It Work? if COMMANDLab6 min
    3. 3Compare with [ ]Lab8 min
    4. 4Test FilesLab7 min
    5. 5&& and ||Lab8 min
    6. 6Choose with caseLab7 min
    7. 7Challenge: The Disk AlarmLab10 min
  4. 04

    Loops

    Repeat work until it is done

    1. 1Tray LabelsLab6 min
    2. 2The Oven TimerLab6 min
    3. 3Only the HostsLab7 min
    4. 4The Register TotalLab7 min
    5. 5Challenge: The Fleet CheckLab15 min
  5. 05

    Functions

    Name a job once and use it everywhere

    1. 1One Banner, Three NotesLab7 min
    2. 2Four Shops, Not SixLab6 min
    3. 3What Does It Cost?Lab7 min
    4. 4One Log for Every ScriptLab7 min
    5. 5Challenge: Refactor DayLab15 min
  6. 06

    Safe Scripts

    Read errors, trace, and stop before damage

    1. 1Read the Error, Then Trace ItLab10 min
    2. 2Clear the Cache, Not Your HomeLab6 min
    3. 3Strict Mode: set -euo pipefail4 min
    4. 4The Nightly JobLab6 min
    5. 5The Price UpdateLab6 min
    6. 6A Clean RestockLab6 min
    7. 7Challenge: Safe at 3 AMLab15 min
  7. 07

    Text in Scripts

    Count, sum, edit and report on logs and data files

    1. 1What Sold MostLab6 min
    2. 2Errors and TotalsLab8 min
    3. 3The Empty shop.confLab6 min
    4. 4Challenge: The Incident ReportLab15 min