FoundationsBeginner8h

Shell scripting.

Bash, pipes, variables, and automating repetitive work.

What is shell scripting?

A shell script is a file of commands the shell runs in order, with variables, conditionals, and loops to make decisions. It is the glue of DevOps — the fast way to automate a task you would otherwise run by hand a hundred times.

Why it matters

DevOps is automation, and the shell is the most universal automation tool there is, present on every Linux box without installing anything. Before reaching for a heavier tool, a clear shell script often does the job. Reading other people's scripts is also a daily reality.

What to learn

  • Shebang lines and making a script executable
  • Variables, quoting, and command substitution
  • Pipes and combining small commands
  • Conditionals, loops, and exit codes
  • Arguments and reading input
  • set -euo pipefail for safer scripts
  • When to graduate from bash to a real language

Common pitfall

Not quoting variables, so a path with a space or an empty value silently breaks the script — or worse, deletes the wrong thing. Quote your expansions ("$var"), and start scripts with set -euo pipefail so errors stop the run instead of charging ahead with bad state.

Resources

Primary (free):

Practice

Write a script that takes a directory as an argument, finds files older than a given number of days, and prints them — then a flag to actually delete them. Quote every variable, use set -euo pipefail, and run it through ShellCheck. Done when ShellCheck reports no warnings.

Outcomes

  • Write an executable script with arguments and exit codes.
  • Combine commands with pipes to solve a task.
  • Quote variables and use set -euo pipefail for safety.
  • Recognize when a task has outgrown bash.
Back to DevOps roadmap