What Is Bash (Bourne Again Shell)?

Su Suriya Ravichandran Updated 06 Dec 2026
5 min read ·Lesson 3 of 205

Bash is a command-line shell and scripting language. Its name stands for Bourne Again Shell, a pun on the original Bourne shell (sh) that it was designed to replace. Brian Fox wrote the first version for the GNU Project, and it was released in 1989 as the shell of the GNU operating system. It is still maintained by the GNU Project, and it became the default shell of most Linux distributions.

Understanding the Concept

Bash does three jobs at once:

  • An interactive shell. It offers a prompt, command history, line editing, and tab completion for people working in a terminal.
  • A scripting language. It provides variables, conditions, loops, functions, and arrays for writing automation.
  • A host for other programs. It starts programs, connects them with pipes and redirections, and manages them as jobs.

Bash was designed to be compatible with the Bourne shell. Most scripts written for sh also run under Bash. At the same time, Bash adds many features that the original shell did not have, which is the "Again" in the name: it takes the Bourne shell idea and goes further.

Features Added Beyond the Bourne Shell

Bash introduced or adopted several features that make both typing and scripting easier.

Command History and Line Editing

Bash remembers commands you ran and lets you recall and edit them with the arrow keys. The history command lists them. Pressing Ctrl+R searches backward through earlier commands.

Tab Completion

Pressing the Tab key completes command names, file names, and in many cases options. This saves typing and reduces mistakes.

Arrays

Bash supports indexed arrays and associative arrays (key and value pairs), which the original Bourne shell lacked:

names=(Asha Ravi Meena)
echo "${names[1]}"
echo "${#names[@]}"

Output:

Ravi
3

The first line creates an array with three elements. Array positions start at zero, so ${names[1]} is the second element, Ravi. The expression ${#names[@]} gives the number of elements.

Extended Conditional Test

Bash offers the [[ ... ]] test, which is more powerful and safer than the older [ ... ] form:

file="report.txt"
if [[ $file == *.txt ]]; then
  echo "This is a text file"
fi

Output:

This is a text file

Inside [[ ]], the right-hand side of == is treated as a pattern, so *.txt matches any name that ends in .txt.

Arithmetic

Bash can calculate integers directly with arithmetic expansion:

echo $((7 * 6))

Output:

42

The $(( ... )) form evaluates the expression inside and substitutes the result.

Process Substitution, Brace Expansion, and More

Bash adds convenient expansions such as {1..5}, which produces the numbers one to five:

echo {1..5}

Output:

1 2 3 4 5

The shell expands the brace pattern into five separate words before echo runs.

Checking That You Are Using Bash

Because Bash has features other shells lack, scripts often need to know which shell is running. Bash stores its version in the variable BASH_VERSION:

echo "$BASH_VERSION"
echo "${BASH_VERSINFO[0]}"

Output on a system with Bash 5.2:

5.2.21(1)-release
5

BASH_VERSION is a string with the full version. BASH_VERSINFO is an array whose first element, index zero, is the major version number. If a script is run by a shell that is not Bash, BASH_VERSION is empty, which makes it a useful check.

Bash as a Program

Bash is an executable program, typically stored at /bin/bash or /usr/bin/bash. You can start it directly to open a new shell inside your current one, or give it a file to run:

bash script.sh

Here, bash is the program and script.sh is its argument. Bash reads the file and executes the commands inside it. To print only the version of the installed Bash, use:

bash --version | head -1

Sample output:

GNU bash, version 5.2.21(1)-release (x86_64-pc-linux-gnu)

The pipe to head -1 keeps only the first line, because the full output also contains licensing text.

The GNU Project and Licensing

Bash is free software released under the GNU General Public License. That means anyone can read its source code, change it, and share it under the same terms. This openness is a major reason Bash spread so widely: Linux distributions could include it freely, and users could rely on it behaving the same way across systems.

Where Bash Fits in the Larger Picture

Bash is not the only shell, and it is not the oldest. It sits in the middle of a family tree of shells:

  • The Bourne shell (sh) came first and set the basic syntax.
  • Bash extended it with arrays, better interactivity, and many conveniences.
  • Other shells such as Zsh and Ksh also built on the same ideas.
  • POSIX, a standard for portable shell scripting, describes the common subset that many shells agree on.

When you write a script with Bash-specific features, you can only rely on it running where Bash is installed. When you stick to the POSIX subset, the script is portable to more shells. A later lesson compares the two approaches in detail.

Bash on Different Systems

Bash is available almost everywhere:

  • Linux: installed by default on most distributions.
  • macOS: includes an old Bash 3.2 for licensing reasons, while newer versions can be installed separately.
  • Windows: available through the Windows Subsystem for Linux or through tools such as Git Bash.

Because versions differ, features added in newer releases, such as some associative array behavior, may not exist on older systems. The lesson on checking your Bash version shows how to handle this.

0 Comments

Reviewed before they appear

No comments yet.

Bash
Introduction to Bash What Is a Shell? What Is Bash (Bourne Again Shell)? Bash vs. Shell vs. Terminal Bash vs. sh, Zsh, and Fish Where Bash Is Used: Linux, DevOps, and Automation Installing Bash on Linux Using Bash on macOS Using Bash on Windows with WSL Checking Your Bash Version Opening and Using a Terminal Running Your First Bash Command Understanding Command Syntax and Arguments Bash Built-in Commands vs. External Commands Working with pwd, ls, and cd Creating Files and Directories with touch and mkdir Copying, Moving, and Renaming Files Removing Files and Directories Safely Viewing Files with cat, less, head, and tail Searching for Files with find Searching Text with grep Understanding File Paths and Wildcards Using man Pages and Command Help Bash Script Structure Creating Your First Bash Script Understanding the Shebang (#!/usr/bin/env bash) Making a Script Executable with chmod Running a Bash Script in Different Ways Writing Comments in Bash Using echo and printf Reading User Input with read Displaying Helpful Messages in Scripts Using Semicolons and Newlines Bash Variables: Declaration and Usage Rules for Naming Bash Variables Environment Variables Local Variables vs. Environment Variables Exporting Variables with export Common Environment Variables: HOME, PATH, USER, and PWD Read-Only Variables with readonly Removing Variables with unset Command-Line Arguments: $0, $1, and More Special Parameters: $#, $?, $$, $!, $@, and $* Positional Parameters and shift Default Values with Parameter Expansion Single Quotes vs. Double Quotes Escaping Special Characters Command Substitution with $(...) Arithmetic Expansion with $((...)) Brace Expansion Tilde Expansion and Home Directories Filename Expansion and Globbing Understanding Word Splitting Parameter Expansion Basics Why Quoting Variables Matters Standard Input, Standard Output, and Standard Error Redirecting Output with > and >> Redirecting Input with < Redirecting Errors with 2> Combining Standard Output and Standard Error Using Pipes (|) to Connect Commands Using tee to Save and Display Output Here Documents with << Here Strings with <<< Command Lists with ;, &&, and || Conditional Statements with if, then, and fi Using elif and else Testing Conditions with test and [ ] Using [[ ]] for Bash Conditionals Comparing Strings in Bash Checking Whether Files Exist Checking File Types and Permissions Integer Comparisons in Bash Logical Operators: &&, ||, and ! Using case Statements Pattern Matching in case Common Conditional Statement Mistakes for Loops in Bash C-Style for Loops while Loops until Loops Looping Through Files and Directories Looping Through Command Output Safely break and continue Nested Loops select Loops for Simple Menus Avoiding Infinite Loops Defining and Calling Bash Functions Passing Arguments to Functions Returning Status Codes from Functions Understanding return vs. echo in Functions Local Variables in Functions Function Scope and Variable Visibility Organizing Scripts into Functions Sourcing Other Bash Files with source Reusable Bash Utility Functions Indexed Arrays in Bash Creating and Accessing Array Elements Adding and Removing Array Elements Looping Through Arrays Array Length and Indices Associative Arrays in Bash Iterating Over Associative Arrays Passing Arrays to Functions Common Array Pitfalls Processing Text with grep, sed, and awk Using cut, sort, uniq, and wc Finding and Replacing Text with sed Extracting Columns with awk Parsing CSV-Like Text from the Command Line Working with Filenames That Contain Spaces Safe File Handling with find -print0 and xargs -0 Temporary Files with mktemp Reading Files Line by Line Appending Logs to a File Understanding Exit Codes Checking Command Success with $? Using exit to End a Script Fail-Fast Scripts with set -e: Benefits and Caveats Using set -u and set -o pipefail Combining Strict Mode Options Safely Handling Errors with if Statements Traps with trap Cleaning Up Temporary Files on Exit Writing Useful Error Messages Debugging Scripts with bash -x Parsing Script Arguments Validating Required Arguments Handling Optional Arguments Parsing Options with getopts Building Help Messages with --help Setting Defaults for Optional Parameters Handling Unknown Options and Invalid Input Creating Interactive Menus in Bash Foreground and Background Processes Running Commands in the Background with & Managing Jobs with jobs, fg, and bg Waiting for Processes with wait Capturing Process IDs with $! and $$ Sending Signals with kill Handling Interrupts and Termination Signals Running Commands with timeout Basic Process Monitoring from Bash Aliases and Shell Functions: When to Use Each Customizing the Bash Prompt (PS1) Bash Startup Files: .bashrc, .bash_profile, and Profile Interactive vs. Non-Interactive Bash Shell Options with set shopt: Enabling Bash-Specific Options Directory Stack with pushd, popd, and dirs Process Substitution with <(...) and >(...) Advanced Parameter Expansion Pattern Matching and Extended Globbing Bash Script Security Fundamentals Avoiding Command Injection in Shell Scripts Quoting User Input Safely Why eval Is Risky and Safer Alternatives Handling Secrets and Credentials in Scripts Using Least Privilege in Automation Scripts Safe Use of rm and Destructive Commands Validating Paths and User-Supplied Filenames ShellCheck: Static Analysis for Bash Scripts Writing Readable and Maintainable Bash Automating Backups with Bash Creating Log Rotation and Cleanup Scripts Checking Disk Usage and Free Space Monitoring CPU, Memory, and System Load Checking Website Availability with curl Automating Updates on Ubuntu and Debian Scheduling Bash Scripts with cron Using Lock Files to Prevent Duplicate Runs Building a Simple Health-Check Script Sending Notifications from Bash Scripts Using Bash in Git Workflows Bash Scripts for Docker Automation Automating Docker Container Health Checks Using Bash in CI/CD Pipelines Environment Configuration for Deployment Scripts Automating SSH Tasks with Bash Deploying a Web Application with a Bash Script Using Bash to Process Application Logs Building Repeatable Development Setup Scripts Bash Debugging Techniques Using set -x and PS4 for Debug Traces Testing Bash Scripts with Bats Mocking Commands During Script Tests Testing Error Paths and Exit Codes Writing Portable Shell Scripts Bash-Specific Syntax vs. POSIX Shell Syntax Using ShellCheck in a Development Workflow Performance Tips for Bash Scripts Build an Interactive Calculator Build a File and Directory Organizer Build a Timestamped Backup Script Build a Log File Analyzer Build a Bulk File Renaming Tool Build a System Resource Monitoring Script Build a Website Uptime Checker Build a User Account Audit Report Build a Database Backup Automation Script Build a Docker Cleanup Helper Build a Server Health-Check and Alert Script Build a Deployment Automation Script Build a Menu-Driven Linux Administration Toolkit Build a Safe Automated Backup and Restore Workflow
Ask about this post
AI Ask about this post

Ask questions about What Is Bash (Bourne Again Shell)? and get answers drawn from it.

Signed-in readers only.