Bash

Bash is the default shell of most Linux systems. A script is a list of commands run from top to bottom, and the pipe | connects them so each program feeds the next. For everyday automation it is linear programming at its most practical.

Paradigm: Linear Programming

What Makes Bash Special

  • Commands, not functions. A line is a program name followed by arguments. Bash launches it, waits for it and moves on. Everything else is glue.
  • Pipelines are linear dataflow. a | b | c streams the output of each command into the next, so a job is described as a sequence of small transformations.
  • Text is the universal type. Files, command output and variables are strings. Tools like grep, sort and awk all agree on lines of text.
  • Exit codes are the decisions. Every command returns 0 for success or non-zero for failure. if, && and || test that code.
  • It has control flow, but scripts are best kept linear. Bash offers if, loops and functions, yet most good scripts are short sequences of commands. When logic grows, move to a structured language such as Python.

Example: Find the three largest entries in a folder

#!/usr/bin/env bash
set -euo pipefail

echo "Largest entries in $PWD:"
du -k * | sort -rn | head -n 3
echo "Done."

How It Works

  • The shebang line #!/usr/bin/env bash tells the system which interpreter runs the file.
  • set -euo pipefail makes the script stop at the first failing command, on unset variables, and on failures inside a pipeline. It is a safe default.
  • The pipeline reads left to right: du measures sizes, sort -rn orders them largest first, and head -n 3 keeps three lines.
  • Nothing loops or branches, and the script does the same steps every time it runs.

History and Where It Is Used

Bash glues together builds, deployments, backups, log processing and developer tooling, and it is the language of CI pipelines and container entry points. It is included in Git for Windows and available on macOS and Linux. See the Bash roadmap for a complete course.

Learn More