ExplainerBeginnerCommand lineUpdated July 12, 2026

What Is Bash? The Bourne Again Shell Explained

A plain-language guide to Bash: what the Bourne Again Shell is, how it reads and runs commands, what makes it powerful, and where it fits versus tools like sh, Zsh, and PowerShell.

Emanuel De AlmeidaJuly 15, 202624 min read

Level

Beginner

Reading time

24 min

Concept

Bash (Bourne Again Shell)

Last reviewed

July 12, 2026

Bash is a shell, the program that reads the commands you type and tells the operating system what to do. Its name stands for Bourne Again SHell, and it's the default command interpreter on most Linux systems. You use it in two ways: interactively, typing commands one at a time at a prompt, and through scripts, files of commands that run automatically. Bash is how people manage Linux and Unix servers, automate repetitive tasks, and chain small programs into bigger workflows. It's free software from the GNU Project, it runs almost everywhere, and it's been a core tool since 1989. This guide explains what Bash is, how it runs a command, what makes it powerful, and where it fits next to other shells and languages.

Key takeaways

  • Bash stands for Bourne Again SHell and is a command interpreter for Unix-like systems.
  • It works two ways: interactively at a prompt, and as a scripting language for automation.
  • It's the default shell on most Linux distributions and is free software from the GNU Project.
  • A shell is not the same as a terminal: the terminal is the window, Bash is the program inside it.
  • It's excellent for gluing commands and automating tasks, but limited for complex programming.

Quick explanation

In simple terms

Bash is the program that reads what you type in a Linux or Unix terminal and makes the computer do it. You can also save commands in a file and have Bash run them for you.

Technical definition

Bash is an sh-compatible command language interpreter for Unix-like systems that executes commands read from a terminal or a file. It supports command-line editing via GNU Readline, job control, shell functions, variables, expansions, pipelines, and redirection, and aims to conform to the IEEE POSIX shell specification.

Analogy

Think of Bash as a translator and dispatcher at a front desk. You hand it a request in shorthand, it figures out what you mean, sends the right worker (program) to do the job, and hands you back the result.

Definition

Bash is a shell, or command language interpreter, for Unix-like systems. Its name stands for Bourne Again SHell. It reads commands you type or store in a script, runs them, and returns the results, and it's the default shell on most Linux distributions.

Bash is a shell, or command language interpreter, for the GNU operating system and other Unix-like systems. The name is an acronym for the Bourne Again SHell, a pun on Stephen Bourne, who wrote the original Unix shell, sh. Bash is largely compatible with sh and adds useful features from the Korn shell (ksh) and the C shell (csh).

A shell is the program that sits between you and the operating system. You give it commands, it works out what you mean, runs the right programs, and shows you the output. Bash does this in two ways: interactively, at a prompt where you type one command at a time, and through scripts, text files full of commands that run start to finish.

Bash was created by Brian Fox in 1989 for the GNU Project as a free software replacement for the Bourne shell. It's now maintained by Chet Ramey and distributed under the GNU General Public License, version 3. The current version is Bash 5.3, released in 2025. Bash aims to conform to the IEEE POSIX shell specification, so scripts written for the standard shell generally run under it.

It's everywhere. Bash is the default shell on most Linux distributions and runs on macOS, the BSDs, and Windows through the Windows Subsystem for Linux, Git Bash, or Cygwin. Note that Apple switched the macOS default to Zsh in 2019, so on a Mac you may need to start Bash yourself.

Why it matters

Bash is one of the foundations of Linux and Unix work. Nearly every server, container, and CI pipeline runs Bash, so understanding it is a core skill for admins, developers, and anyone who automates tasks on Unix-like systems.

Core concepts

A shell is a command interpreter

A shell reads commands and tells the operating system what to run; Bash is one such shell.

A shell is the layer between you and the operating system kernel. You give it a line of text, and it works out which program to run, starts it, and shows you the output. Bash is one shell among several, including sh, Zsh, and fish.

This is the first thing to get straight. The shell isn't the window you type into, and it isn't the whole operating system. It's a specific program whose job is to read commands and run them. When you open a terminal on Linux, Bash is usually the program waiting at the prompt.

Example

You type a command, and Bash finds the matching program on your system and runs it.

Why it matters — Knowing the shell is a distinct program clears up most beginner confusion about the command line.

Two roles: interactive and scripting

Bash works both at a live prompt and by running commands stored in a script file.

Bash has two modes that matter. Interactive mode is the prompt where you type one command at a time and see the result, with conveniences like history, tab completion, and line editing. Scripting mode runs a file of commands from top to bottom, with no one watching.

Scripting is where Bash earns its keep. You put a sequence of commands in a file, mark it executable, and run it whenever you need that work done. That's how backups, deployments, and routine maintenance get automated instead of typed out by hand each time.

Example

A script named backup.sh runs a fixed set of commands every night without anyone typing them.

Why it matters — The scripting role is what turns Bash from a prompt into an automation engine.

How Bash runs a command

Bash reads input, splits it into words, expands it, parses it, runs it, and returns an exit status.

When you press Enter, Bash goes through a set sequence. It reads the line, breaks it into words separated by spaces and special characters, expands things like variables and patterns, parses the result into commands, sets up any input and output redirection, then runs the command.

Every command returns an exit status, a number that says whether it succeeded. Zero means success; anything else means an error. Scripts use that status to decide what to do next, which is how Bash handles conditions and error checking.

Example

Bash expands a wildcard into a list of filenames before handing them to the command.

Why it matters — Understanding the sequence explains why quoting and spaces behave the way they do.

Builtins, external commands, and PATH

Some commands are built into Bash; most are separate programs found using the PATH variable.

Bash runs two kinds of commands. Builtins like cd, echo, and export are part of Bash itself and run inside it. External commands like ls, grep, and python are separate programs stored on disk.

To find an external command, Bash searches the directories listed in the PATH environment variable, in order, and runs the first match. That's why a program has to be on your PATH to run by name, and why two programs with the same name can behave differently depending on PATH order.

Example

Typing 'ls' makes Bash search PATH, find /usr/bin/ls, and run it.

Why it matters — PATH is behind many 'command not found' problems and is key to how commands resolve.

Pipes, redirection, and expansions

Bash can connect programs together, redirect their input and output, and expand text before running it.

This is where Bash gets powerful. A pipe (|) sends one program's output straight into the next, so you can build a chain of small tools. Redirection (> and <) points a program's output to a file or feeds it input from one. Expansions rewrite your text first, filling in variables, matching filenames with wildcards, and substituting the output of other commands.

Together these let you compose short, expressive one-liners. You can filter, sort, and transform data by wiring simple programs together, which is the classic Unix way of working.

Example

A pipeline lists files, filters for a word, and counts the matches, all in one line.

Why it matters — Composition through pipes and expansions is the core of Bash's day-to-day power.

Variables, environment, and startup files

Bash uses variables and environment settings, configured through startup files like .bashrc.

Bash stores values in variables and shares some of them with programs it runs through the environment, including PATH and HOME. You set your own variables for scripts and for shaping how the shell behaves.

When Bash starts, it reads startup files to set up your session. Interactive shells commonly read ~/.bashrc, and login shells read files like ~/.bash_profile and /etc/profile. That's where people put aliases, PATH changes, and prompt customizations so their shell works the way they like.

Example

Adding a directory to PATH in ~/.bashrc makes its programs runnable by name in every new shell.

Why it matters — Startup files and the environment shape every session, so they're key to a usable setup.

How it works

1

Read the input

Bash reads a line of input, from the prompt in interactive mode or from a script file. Comments beginning with # are ignored.

Read

Example — You type a command and press Enter, or Bash reads the next line of a script.

2

Split into words and expand aliases

Bash breaks the line into words, separated by spaces and special characters called metacharacters, then applies any alias expansion.

Tokenize

Example — The line 'ls -l /tmp' becomes the words ls, -l, and /tmp.

3

Parse into commands

Bash groups the words into simple and compound commands, recognizing pipelines, lists, loops, and other structures.

Parse

Example — 'cmd1 | cmd2' is parsed as a pipeline of two commands.

4

Perform expansions

Bash performs its expansions: brace, tilde, parameter and variable, command substitution, arithmetic, word splitting, and filename (wildcard) expansion.

Expand

Example — A '*.txt' pattern expands into the list of matching filenames.

5

Set up redirections

Bash applies any input and output redirections, connecting the command to files or to other commands through pipes.

Redirect

Example — '> out.txt' points the command's output into the file out.txt.

6

Run the command and return a status

Bash runs the command, either as a builtin inside itself or by finding an external program on the PATH, then returns an exit status that scripts can act on.

Execute

Example — The program runs, prints output, and returns 0 for success or non-zero for an error.

Use cases

Automating repetitive tasks

Admins, developers

Put routine work into scripts that run on demand or on a schedule.

A nightly script backs up files, rotates logs, and cleans temp folders, triggered by cron without anyone typing the commands.

Benefit — Saves time and removes human error from tasks done over and over.

System and cloud administration

System and cloud admins

Manage servers by logging in and running commands to configure, inspect, and troubleshoot.

An admin checks services, edits config, and restarts a daemon across servers from the shell.

Benefit — Gives precise, reproducible control over Linux and Unix systems.

Developer workflows

Software developers

Build, test, and deploy code, and set up a consistent dev environment with dotfiles.

A build script compiles the project, runs tests, and packages the result in one command.

Benefit — Standardizes everyday dev tasks so they're fast and repeatable.

CI/CD and DevOps pipelines

DevOps engineers

Drive the steps of continuous integration and delivery pipelines and container builds.

A pipeline stage runs a Bash script to lint, test, and publish an artifact.

Benefit — Provides a common, portable way to script pipeline stages across tools.

Ad-hoc file and data wrangling

Developers, data professionals

Filter, sort, and transform files and text by piping together small command-line tools.

A pipeline of grep, sort, and uniq counts the most common errors in a log file.

Benefit — Turns quick data questions into fast one-liners without writing a full program.

Benefits

It's everywhere

Bash is the default shell on most Linux systems and available on macOS, BSD, and Windows via WSL.

A Bash script written on one Linux box usually runs on another with no changes.

Built in, no extra tooling

It ships with the operating system, so there's nothing to install to start automating.

You can write and run a script on a fresh Linux server immediately.

Powerful composition

Pipes and redirection let you wire small programs into larger workflows with little code.

A single line can filter, sort, and summarize a large log file.

Great for automation

Scripting turns repetitive manual work into reliable, repeatable jobs.

One script replaces a dozen manual steps run every deployment.

Huge knowledge base

Decades of use mean vast documentation, examples, and a large pool of people who know it.

Most command-line problems have well-known, searchable solutions.

Limitations

Error-prone syntax

Medium

Quoting, spaces, and word splitting have subtle rules. Small mistakes, like an unquoted variable with a space, can cause surprising bugs.

Workaround — Quote variables, use a linter like ShellCheck, and enable strict options in scripts.

Weak for complex programs

Medium

Bash has limited data structures and clumsy handling of anything beyond text and simple arrays. Complex logic gets hard to read and maintain fast.

Workaround — Reach for a general-purpose language like Python once logic or data gets involved.

Portability pitfalls

Medium

Bash-only features, sometimes called bashisms, don't run under plain POSIX sh. A script that works in Bash may fail on a minimal shell like dash.

Workaround — Target strict POSIX sh when portability matters, and test with a checker for bashisms.

Security footguns

High

Unquoted input, use of eval, and building commands from untrusted data can lead to command injection. Scripts running as root raise the stakes.

Workaround — Validate and quote input, avoid eval, and keep Bash patched.

Process overhead at scale

Low

Bash starts a new process for each external command. Loops that spawn many programs can be slow on very large inputs.

Workaround — Use built-in features, batch operations, or a single program for heavy data processing.

Architecture

Bash sits between the user and the operating system kernel. A few parts do the work: a line reader for interactive input, a parser that turns text into commands, an expansion engine, an executor that runs builtins or launches external programs, plus job control and history. Seeing these parts makes it clear how a typed line becomes a running program and its output.

Readline (line editor)

Provides interactive command-line editing, history, and tab completion at the prompt.

Pressing the up arrow recalls your previous command.

Parser

Turns the input text into words and then into simple and compound commands.

Recognizes a pipeline, an if statement, or a for loop.

Expansion engine

Rewrites the command with variables, wildcards, and command substitution before it runs.

Turns $HOME into your home directory path.

Executor

Runs builtins inside Bash or launches external programs found on the PATH.

Runs cd internally, but launches /usr/bin/grep as a separate process.

Job control

Manages foreground and background jobs, letting you pause, resume, and background commands.

Running a task in the background with & while you keep working.

Data flow

Input arrives from the prompt or a script. The parser breaks it into commands, the expansion engine fills in variables and patterns, and redirections are set up. The executor then runs each command, either as a builtin or by asking the kernel to start an external program found on the PATH. Output flows back to the terminal or into a pipe or file, and each command returns an exit status the shell can use.

Integrations: Terminal emulators (the window Bash runs in), Linux, macOS, and the BSDs, Windows via WSL, Git Bash, or Cygwin, CI/CD systems and Docker containers, Core Unix tools like grep, sed, awk, and coreutils

Architecture limitations

The shell is a coordinator, not a heavy compute engine. For each external command it starts a new process, so very large loops that spawn many programs can be slow compared with a single program written in a compiled or scripting language.

Examples

A quick one-line pipeline

You want to find the most common error messages in a large log file.

You pipe three small tools together: one to filter lines containing 'ERROR', one to sort them, and one to count duplicates. Bash wires the output of each into the next, and you get a ranked list in a single line, no script needed.

OutcomeA ranked count of the most frequent errors appears in seconds.

A small automation script

You want to back up a folder every night without typing the steps.

You write the commands into a file, add a shebang line so the system knows to run it with Bash, mark it executable, and schedule it with cron. A loop and an if check let it skip files that haven't changed. Now the task runs itself.

OutcomeThe backup runs on schedule, reliably and hands-free.

An interactive session

You're exploring a system and trying commands one at a time.

At the prompt, you set a variable, use tab completion to finish a long path, recall a previous command from history, and redirect output to a file. This is Bash's interactive side, where the conveniences make hands-on work fast.

OutcomeYou move quickly through tasks with editing, history, and completion helping you.

Comparisons

Bash vs sh (the Bourne/POSIX shell) vs sh (Bourne shell / POSIX shell)

sh is the original Unix shell and the POSIX standard shell. Bash is a superset: it runs most sh scripts and adds features like arrays, better expansions, and command-line editing. Code that uses Bash-only features won't run under a strict sh.

CriterionBash vs sh (the Bourne/POSIX shell)sh (Bourne shell / POSIX shell)
Scopesh plus many extra featuresThe minimal standard shell
PortabilityWidely available but not always present as /bin/shPresent on virtually every Unix-like system
UseRich interactive use and scriptingMaximum portability for scripts

When to choose — Use Bash for features and comfort; target strict sh when a script must run everywhere.

Bash vs Zsh vs Zsh (Z shell)

Both are interactive shells and share most syntax. Zsh adds richer completion, theming, and plugins, and it's the default on macOS since 2019. Bash is the default on most Linux systems and is more universally present on servers.

CriterionBash vs ZshZsh (Z shell)
Default onMost Linux distributionsmacOS (since Catalina)
Interactive extrasSolid, more minimalRicher completion, themes, plugins
Ubiquity on serversVery highCommon but less universal

When to choose — Zsh shines for interactive comfort; Bash is the safer default for portable server scripts.

Bash vs PowerShell vs PowerShell

Bash passes plain text between programs and rules the Unix world. PowerShell, from Microsoft, passes structured objects and is the native automation shell on Windows. PowerShell is now cross-platform, but each is strongest on its home turf.

CriterionBash vs PowerShellPowerShell
Passes between commandsText streamsStructured objects
Home platformLinux and UnixWindows

When to choose — Use Bash for Linux and Unix automation; use PowerShell for native Windows management.

Myths, corrected

Myth

Bash and the terminal are the same thing.

Correction

They're different. The terminal, or terminal emulator, is the window that shows text and takes keystrokes. Bash is the program running inside it that reads and executes your commands. You can run a different shell in the same terminal.

Why it happens: Beginners meet both at once, so the window and the shell blur together.

Myth

Bash only runs on Linux, and Bash is basically Linux.

Correction

Bash is a program, not an operating system. It runs on Linux, macOS, the BSDs, and Windows through WSL, Git Bash, or Cygwin. And Linux can use other shells, like Zsh or fish, instead of Bash.

Why it happens: Bash is the default on most Linux systems, so people equate the two.

Myth

Bash is the default shell on macOS.

Correction

Not anymore. Apple made Zsh the default interactive shell in macOS Catalina in 2019, mainly to avoid the GPLv3 license of newer Bash. macOS still ships an old Bash 3.2, and you can switch back if you want.

Why it happens: macOS used Bash for many years, so the change surprises longtime Mac users.

Myth

Bash is a full programming language like Python.

Correction

Bash is a command and scripting language, and it's superb at gluing programs and automating tasks. But it's awkward for complex data and logic. Once a script gets involved, a general-purpose language is usually the better tool.

Why it happens: Bash can do loops, conditions, and functions, so it looks like a general language.

Practical implications

For admins

Bash is the daily driver for Linux and Unix administration. Learn quoting and safe scripting habits early, since small syntax slips cause real bugs. Scripts make routine operations repeatable and auditable.

For MSPs

For teams managing many Linux hosts, Bash is the common language for fleet automation. Standardize scripts, mind portability across distributions, and version-control them so changes are tracked.

For business

Bash is free software with a large talent pool, so the cost is mainly training. Its value is the time saved by automating repetitive work and the reliability of scripted processes.

For security

Treat shell input carefully. Quote variables, avoid eval, and never build commands from untrusted data, since that invites command injection. Keep Bash patched, and be extra careful with scripts that run as root.

For end users

Most end users never see Bash. Developers and power users use it directly; for everyone else it works quietly behind graphical tools and installers.

Cost impact

Bash is free software under the GPL, so there's no license cost. The real investment is the learning curve and the time to write and maintain good scripts.

Operational impact

Bash underpins Linux operations, CI/CD, and container builds, so a faulty script can have wide reach. Test scripts, use strict options, and review them like any other code.

Decision guide

Use when

  • You're automating repetitive tasks on a Unix-like system
  • You want to chain command-line tools into a workflow
  • You're administering Linux or Unix servers
  • You want a scripting tool that's already installed everywhere on Linux

Avoid when

  • You need complex data structures or heavy application logic (use Python)
  • You're automating native Windows tasks (use PowerShell)
  • You need a script to run unchanged on every shell (target strict POSIX sh)
  • You're processing very large datasets where per-command overhead matters

Requirements

  • A Unix-like environment, or WSL / Git Bash / Cygwin on Windows
  • Bash installed (it usually is on Linux)
  • Basic command-line familiarity
  • For safe scripts, habits like quoting and a linter such as ShellCheck

Alternatives

  • POSIX sh or dash for maximum script portability
  • Zsh or fish for a richer interactive experience
  • PowerShell for native Windows automation
  • Python for complex logic and data handling
Use Bash when you're working on Linux or Unix and want to run commands or automate tasks by gluing programs together. Stick with strict POSIX sh when a script must run on every shell, and switch to a language like Python once logic and data get complex. On Windows, PowerShell is the native choice.

Related terms

Shell

The program that reads commands and runs them on an operating system; Bash is one shell.

Bourne shell (sh)

The original Unix shell by Stephen Bourne, and the POSIX standard shell that Bash is compatible with.

Shell script

A text file of shell commands that runs top to bottom, used to automate tasks.

POSIX

The IEEE standard for Unix-like systems, including the shell specification Bash aims to conform to.

Terminal emulator

The window that displays text and takes keystrokes; the shell runs inside it.

Zsh

The Z shell, a Bash-compatible interactive shell with extra features, and the default on macOS since 2019.

Frequently asked questions

What does Bash stand for?

Bash stands for Bourne Again SHell. The name is a pun on Stephen Bourne, who wrote the original Unix shell, sh, that Bash was created to replace and improve on.

What is Bash used for?

Two things. Interactively, it's the prompt where you type commands to run programs and manage a system. As a scripting language, it runs files of commands to automate repetitive tasks like backups, deployments, and maintenance.

Is Bash the same as the terminal?

No. The terminal, or terminal emulator, is the window that shows text and takes your keystrokes. Bash is the program running inside it that reads and executes your commands. You can run other shells in the same terminal.

Does Bash only run on Linux?

No. Bash is a program that runs on Linux, macOS, the BSDs, and Windows through WSL, Git Bash, or Cygwin. It's the default shell on most Linux distributions, but Linux can use other shells too.

Is Bash still the default shell on macOS?

No. Apple switched the default interactive shell to Zsh in macOS Catalina in 2019, largely to avoid the GPLv3 license of newer Bash versions. macOS still includes an older Bash, and you can switch back if you prefer.

What's the difference between Bash and sh?

sh is the original Bourne shell and the POSIX standard shell. Bash is a superset that runs most sh scripts and adds features like arrays and command-line editing. Scripts using Bash-only features won't run under a strict sh.

Bash or Zsh: which should I use?

Both are capable interactive shells with similar syntax. Zsh offers richer completion and theming and is the macOS default. Bash is the default on most Linux systems and is more universally present on servers, which makes it a safer choice for portable scripts.

What's the latest version of Bash?

The current version is Bash 5.3, released in 2025. It's maintained by Chet Ramey and distributed by the GNU Project under the GNU General Public License, version 3.

Conclusion

Bash, the Bourne Again SHell, is the command interpreter for most Linux and Unix systems. It works interactively at a prompt and as a scripting language for automation. When you run a command, Bash reads the line, splits and expands it, sets up redirection, then runs a builtin or an external program found on the PATH, returning an exit status.

Its strengths are ubiquity, composition through pipes, and painless automation, all for free. Its limits are error-prone syntax, weak support for complex data, and portability quirks, so reach for a language like Python when logic gets involved and PowerShell for native Windows. Remember the basics: a shell isn't a terminal, Bash isn't only for Linux, and on macOS the default is now Zsh.

Main takeaway

Bash is the shell and scripting language behind most Linux and Unix work. Learn how it reads and runs commands, and you have a tool for almost any automation on a Unix-like system.

If you're ready to use Bash, a hands-on tutorial on writing your first safe script, with a shebang and strict options, is the natural next step. To compare shells in depth, look at Bash versus Zsh for interactive use, or Bash versus PowerShell across platforms.

Reader reviews

Rate this articleBe the first to rate
No written reviews yetRate the article above, or be the first to share your experience.

Related articles