Terminal GuideTerminal Guide

Bash

GNU Bourne-Again Shell

Most popular shell, standard on Linux systems with rich scripting capabilities

POSIX CompliantReleased: 1989Official Site

Overview

Bash (GNU Bourne-Again Shell) is the default shell on most Linux distributions and was the default on macOS until Catalina. Created by Brian Fox in 1989 as a free software replacement for the Bourne shell, Bash has become the de facto standard for shell scripting.

Quick Facts

Full NameGNU Bourne-Again Shell
CategoryPosix
POSIX CompliantYes
Config File.bashrc / .bash_profile
Default OnMost Linux distributions, macOS (before Catalina)
First Release1989

Who Should Use Bash?

  • System administrators - Automation and server management
  • Developers - Build scripts and development workflows
  • Linux users - Default interactive shell on most systems
  • Script writers - Portable scripts across Unix-like systems

Installation

Bash is pre-installed on most Unix-like systems.

bash
# Check Bash version
bash --version

# Install on macOS (if needed)
brew install bash

# Install on Debian/Ubuntu
sudo apt install bash

# Set as default shell
chsh -s /bin/bash

Basic Usage

Basic Bash commands and syntax.

bash
# Variables
NAME="World"
echo "Hello, $NAME!"

# Arrays
fruits=("apple" "banana" "cherry")
echo ${fruits[0]}  # apple

# Conditionals
if [ -f "file.txt" ]; then
  echo "File exists"
fi

# Loops
for i in {1..5}; do
  echo "Number: $i"
done

Configuration

Bash configuration files and customization.

bash
# ~/.bashrc - Interactive non-login shells
# ~/.bash_profile - Login shells

# Add to ~/.bashrc
export PS1="\u@\h:\w\$ "  # Custom prompt
export PATH="$HOME/bin:$PATH"

# Aliases
alias ll='ls -la'
alias gs='git status'

# Reload configuration
source ~/.bashrc

Key Features

Command History

Access previous commands with arrow keys and history command

Tab Completion

Auto-complete file names, commands, and arguments

Job Control

Run processes in background with & and manage with fg/bg

Scripting

Full programming language with functions, arrays, and control structures

FAQ

What is the difference between .bashrc and .bash_profile?

.bash_profile is executed for login shells, while .bashrc is executed for interactive non-login shells. On macOS, .bash_profile is typically used; on Linux, both are common.

Is Bash POSIX compliant?

Bash is mostly POSIX compliant but includes many extensions. Use "bash --posix" or "set -o posix" for strict POSIX mode.

Summary

Key takeaways for Bash:

  • Most widely used shell with extensive documentation
  • Pre-installed on almost all Linux distributions
  • Powerful scripting capabilities with POSIX compatibility
  • Large ecosystem of tools and frameworks

Official Documentation

For authoritative information, refer to the official documentation:

Written by Dai AokiPublished: 2026-01-20

Related Articles