The most detailed free FDE + DevOps library: 140+ lessons, 70+ labs and 80 long-form articles, in English and Turkish. Start learning →

DevOps Foundations · Module 3: Safe automation with Bash and Python · Lab

Fix the Shell Script That Spaced Filenames Break

40 min hands-on · Core

Local Linux shell with ShellCheck installed or via shellcheck.net; training directory /tmp/dlab-m03-01.

Two ways to do this lab: in your browser on Killercoda (free, no install), or on your own machine as a local guide. Killercoda runs one free scenario at a time: if you see a waiting queue, close other Killercoda tabs and wait a minute.

Objectives

  • Reproduce a word-splitting failure with spaced filenames
  • Repair with quoting, globs and set -euo pipefail
  • Prove the repair with a failing-then-passing test plus a clean ShellCheck run
  1. Step 1

    Take the broken script

    Use the ls-parsing backup loop from lesson 1 (or any loop-over-files script you own) against a training directory holding names like 'Q3 report (final).txt' and '-leading-dash.log'. Record exactly what breaks: wrong file count, created fragments, or errors.

  2. Step 2

    Repair for adversarial names

    Rewrite with a glob (never parsed ls), quoted expansions, -- argument guards, and set -euo pipefail. Run ShellCheck and clear every warning, not just errors.

  3. Step 3

    Test both outcomes

    Write a test that first fails against the broken version (proving it tests something) then passes against the repair, covering spaced names and a leading dash. Keep the test beside the script.

How to confirm it worked

  • The breakage is reproduced and quoted before the repair
  • Every expansion in the repaired script is quoted; guards present
  • ShellCheck reports zero warnings on the final script
  • The test fails on the broken version and passes on the repair