Skip to main content
Bash beginner Lesson 1 of 22

Introduction to Bash

Understand what Bash is, how it differs from a terminal and shell, and why it's the backbone of DevOps and automation.

What Is Bash?

Bash stands for Bourne Again SHell. It was written by Brian Fox for the GNU Project in 1989 as a free replacement for the original Bourne shell (sh). Today it ships as the default interactive shell on virtually every Linux distribution and was the default on macOS until Catalina (which switched to zsh). Understanding Bash means understanding the language that underlies the majority of server automation, CI/CD pipelines, and DevOps tooling in use today.

Bash is two things at once:

  • A command language — a programming language designed around running programs and manipulating files.
  • An interactive shell — the program that reads your keystrokes, interprets them, and prints results.

Terminal vs Shell vs Bash

These three terms are often used interchangeably but they mean different things. Mixing them up leads to confusion when you’re trying to troubleshoot why a script behaves differently in different environments.

TermWhat it actually is
TerminalThe window/application (iTerm2, GNOME Terminal, Windows Terminal). It handles rendering text and capturing keyboard input.
ShellThe interpreter running inside the terminal. It reads commands and executes them. Examples: bash, zsh, fish, dash.
BashOne specific shell implementation — the one you’ll use on almost every Linux server in production.

Think of the terminal as the TV set and the shell as the channel. Bash is one specific channel.

Why Bash Matters in DevOps and Automation

CI/CD Pipelines

Every GitHub Actions workflow, GitLab CI job, and Jenkins build step ultimately runs shell commands. Even when the pipeline YAML looks high-level, the runner drops into bash to execute your steps. Knowing Bash means you can write, debug, and optimize these steps directly rather than treating them as a black box.

# .github/workflows/deploy.yml (the run: block is bash)
- name: Build and push Docker image
  run: |
    docker build -t myapp:${{ github.sha }} .
    docker push myapp:${{ github.sha }}

Server Provisioning and Bootstrap

When a cloud VM first boots, it runs a bash script to install packages, configure services, and prepare the environment. AWS EC2 user-data, GCP startup scripts, and Azure custom script extensions are all bash. This script runs before any configuration management tool like Ansible or Chef, making it the first line of server setup.

#!/usr/bin/env bash
# EC2 user-data: runs once on first boot
set -euo pipefail

apt-get update -y
apt-get install -y nginx
systemctl enable --now nginx
echo "Bootstrap complete" >> /var/log/bootstrap.log

Automation and Scripting

Bash is the glue language of Unix. It orchestrates tools like grep, awk, sed, curl, and jq into workflows that would take hundreds of lines in a general-purpose language. The ability to compose these tools into pipelines is one of the most powerful ideas in computing.

# Find all services returning non-200 status codes
while IFS= read -r url; do
  status=$(curl -s -o /dev/null -w "%{http_code}" "$url")
  [[ "$status" != "200" ]] && echo "ALERT: $url returned $status"
done < services.txt

Log Analysis

Production engineers spend significant time parsing logs. Bash pipelines with grep, awk, and sort can answer complex questions in seconds without loading data into a database. The ability to query logs directly on the server is a critical skill for incident response.

# Top 10 IPs hitting your nginx server
awk '{print $1}' /var/log/nginx/access.log \
  | sort | uniq -c | sort -rn | head -10

How Bash Fits Into the Bigger Picture

Understanding the execution chain helps you reason about where failures occur and what context your scripts run in.

User types command

   Terminal (renders UI)

   Bash (interprets command)

   Kernel (executes system calls)

   Hardware

Bash sits between you and the operating system kernel. It translates human-readable commands into the system calls that create processes, open files, and move data.

Bash vs Other Shells

Bash is not the only shell, but it is the most widely deployed on Linux servers. Knowing where the alternatives fit helps you make the right choice for each context.

ShellNotes
bashDefault on Linux, available everywhere, POSIX-compatible plus extras
zshDefault on macOS since Catalina; better interactive features, compatible with most bash scripts
fishUser-friendly, great autocomplete, but intentionally not POSIX-compatible
dashMinimal, fast, strict POSIX — used as /bin/sh on Debian/Ubuntu for boot scripts
kshKorn shell, common in enterprise Unix (AIX, Solaris)

For scripting that runs on servers, always target bash explicitly — do not rely on /bin/sh unless you intentionally want POSIX-only portability.

Your First Bash Command

The best way to get comfortable with Bash is to start running commands. Open a terminal and try these — they verify your environment and show you basic output.

echo "Hello, Bash!"
# Hello, Bash!

# Check which bash you're running
which bash
# /usr/bin/bash  (or /bin/bash on some systems)

bash --version
# GNU bash, version 5.2.x

What Bash Is Not Good At

Knowing when not to use Bash is just as important as knowing how to use it. Reach for Python, Go, or another language when you need:

  • Complex data structures (hash maps of arrays, nested objects)
  • HTTP clients with proper error handling and JSON parsing
  • Floating-point arithmetic (Bash only does integers natively)
  • Code that needs to be unit tested and maintained long-term by a team

The rule of thumb: if your bash script exceeds ~200 lines or needs real error handling beyond set -e, consider rewriting it in Python.

What’s Next

The next tutorial covers getting Bash set up on your system — whether you’re on Linux, macOS, or Windows via WSL — and writing your very first script.

Frequently Asked Questions

Is Bash still relevant in 2025?
Absolutely. Bash is the default shell on nearly every Linux server and macOS machine. CI/CD pipelines, Docker entrypoints, Kubernetes init containers, and cloud bootstrap scripts are overwhelmingly written in Bash.
Should I learn Bash or Python for automation?
Learn both. Bash excels at gluing Unix tools together, file manipulation, and tasks where spawning processes is the main work. Python wins when you need data structures, HTTP calls, or logic that would be painful in Bash.
What is the difference between sh and bash?
sh is the POSIX-standard shell. Bash (Bourne Again SHell) is a superset of sh with extra features like arrays, [[ ]], and process substitution. Most scripts use bash explicitly via the shebang #!/usr/bin/env bash.