Bash. GNU Bourne Again Shell

A concise guide for students and makers. Understand the shell, run commands with confidence and write small scripts that save time.

Illustrative image for Bash guide

What Bash does

Bash reads input, runs programs and connects them with pipes. It keeps a history and supports completion. It can act as an interactive tool or as a language for scripts. Most Linux distributions ship it as a default login shell. It is also present on macOS and can run on Windows through WSL or Git Bash.

Core commands

# list files
ls -al

# print the path
pwd

# change directory
cd project

# show the first lines of a file
head -n 20 README.md

# search text in files
grep -R "pattern" src/

Pipes and redirection

# pass output of one program to another
ps aux | grep python

# save output to a file
make build > build.log 2>&1

# append to a log
echo "done" >> build.log

Safer scripts

#!/usr/bin/env bash
set -Eeuo pipefail
IFS=$'\n\t'

main(){
  local name=${1:-world}
  echo "hello $name"
}
main "$@"

Variables and loops

name="Alice"
echo "Hi $name"

for f in *.txt; do
  wc -l "$f"
done

Install and check

Open a terminal and run bash --version. On Linux it is already installed. On macOS it ships with the system and you can install a newer build with your package manager. On Windows you can enable WSL or install Git for Windows which includes Git Bash.

Tip. Keep your shell up to date and read the changelog for new features. Some scripts depend on features that appear in later versions.

Learn more

Read the manual with man bash. Explore the Bash Reference Manual. Practice with small scripts. Use shellcheck to catch common issues and quote variables to avoid word splitting. Prefer long options when available so scripts are easier to read.

Frequently asked questions

Is Bash the same as sh

Bash is compatible with the older sh and adds many features. When writing portable scripts target POSIX sh or run in Bash with POSIX mode.

Can I change my login shell

Yes on Unix like systems you can use the chsh command to pick a shell. You need a valid entry in the list of allowed shells.

Where to report bugs

Use the official project channels. Include your version and a small script that reproduces the issue.