Dualo
Bash / Shell Scripting

What is Bash?

A command interpreter and scripting language — the glue of Unix systems. You type commands; it runs programs, pipes data, and automates tasks.

1 min read

Bash is a POSIX-compatible shell and scripting language, originally written by Brian Fox (1989) as a free replacement for the Bourne shell (sh). It implements command-line editing (readline), history, job control, arrays, arithmetic, process substitution, and a large set of built-ins beyond POSIX.

Execution model: Bash reads input line by line (or until a complete command), tokenizes, performs expansions in a fixed order (brace → tilde → parameter → command substitution → arithmetic → word splitting → pathname), then fork+execs external binaries or runs built-ins. Each external command runs in its own process; the shell waits (unless backgrounded with &).

Shell families: sh (POSIX baseline, often dash on Debian/Ubuntu), bash (GNU, feature-rich, default on most Linux), zsh (macOS default since Catalina, extended globbing, better completion), ksh (Korn, enterprise Unix), fish (not POSIX, friendlier syntax). Scripts targeting portability should declare #!/bin/sh and stick to POSIX features; #!/usr/bin/env bash unlocks Bash-specific extensions.

Built-ins vs external commands: cd, echo, read, export, [[ are built-ins — they execute inside the shell process, no fork. ls, grep, sed are external binaries in /usr/bin. type -a <cmd> reveals what a name resolves to; built-ins win over same-named binaries.

Environment: Bash maintains a hierarchy of scopes — environment variables (inherited from parent, exported to children), shell variables (local to the shell), function locals. Config loads: /etc/profile~/.bash_profile (login), ~/.bashrc (interactive non-login). Understanding which file to edit matters on macOS vs. Linux vs. SSH sessions.

Bash 3 vs 4 vs 5: macOS ships Bash 3.2 (GPL-v2 era) — no associative arrays (declare -A), no mapfile, no ${var^^}. Linux and Homebrew provide Bash 5.x. Scripts that use Bash-4+ features must declare the dependency (#!/usr/bin/env bash + version check).

Grounded on https://www.gnu.org/software/bash/manual/bash.html

Next up

Shell basics — navigation & files

The core commands you use every day: moving around the filesystem, listing, reading, copying, and inspecting files.