Lesson 1 / 25
What Bash Is
Explain what a shell does and how Bash relates to sh, zsh and POSIX.
A command interpreter and a language
A shell reads commands, either typed interactively or from a file, and runs programs for you. It also expands variables and wildcards, connects programs with pipes and redirects input and output. Bash (the Bourne Again SHell, from the GNU project) is the most widely used shell for scripting: it is the default login shell on most Linux distributions and is installed almost everywhere, including in CI runners and containers. Bash implements the POSIX shell standard plus many extensions: [[ ]] tests, arrays, $(( )) arithmetic, local, process substitution and more. Other shells: sh is the POSIX shell, which on Debian and Ubuntu is dash (small and fast, without Bash extensions); zsh is the default interactive shell on macOS and is popular interactively; fish focuses on usability but is not POSIX-compatible. Current Bash is version 5.x, but macOS ships the old Bash 3.2, which lacks associative arrays and other features, something to remember when scripts must run on Macs.
Where the shell sits
The shell sits between you (or a script) and the operating system, launching programs and wiring them together.
Which shell am I using?
Interactive shell, script interpreter and versions can all differ.
echo "$SHELL" # your login shell (not necessarily the one running now)
echo "$BASH_VERSION" # set only when running inside bash
ps -p $$ -o comm= # the shell process running this command
ls -l /bin/sh # on Debian/Ubuntu: a link to dash
bash --version | head -1
# run a script explicitly with bash, regardless of your interactive shell
bash ./deploy.shBash scripts need bash, not sh
Running a Bash script with sh script.sh on Ubuntu uses dash, which fails on [[, arrays and other Bash features with confusing errors. Use a #!/usr/bin/env bash line and run the script directly.
Quick check: On Ubuntu, what does /bin/sh usually point to?
- dash
- bash
- zsh
- fish
Answer
dash — Debian and Ubuntu use dash as /bin/sh for speed and strict POSIX behaviour.