Linux Command Reference ยท Concepts
Bash, dash, zsh and fish compared
Compare the main Linux shells: Bash, dash, zsh, fish, ksh and BusyBox ash. Differences in scripting, interactivity, speed, defaults and which to use for what.
A shell is the program that reads your commands, expands them and starts other programs. It plays two roles: an interactive tool (prompt, history, completion) and a scripting language. Several shells exist because people weigh those two roles differently. Bash is the default almost everywhere on Linux, but dash, zsh, fish and others all matter in practice.
Your login shell is stored in /etc/passwd; the shell running a script comes from its shebang line or the command that launched it. They can be different shells.
echo "$SHELL" # login shell (not necessarily the running one) ps -p $$ -o comm= # the shell running right now cat /etc/shells # installed login shells
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
The shells at a glance
| Shell | Role | Strengths | Watch out for |
|---|---|---|---|
| Bash | Default on most distributions | Ubiquitous, rich scripting (arrays, associative arrays, [[ ]], process substitution), huge documentation |
macOS ships 3.2; some features differ by version |
| dash | /bin/sh on Debian and Ubuntu |
Very small and fast start-up; strict POSIX | Almost no extras: no arrays, no [[ ]], no {1..3} |
| zsh | Default on macOS; popular interactive shell | Excellent completion, globbing (**/*(.)), themes via frameworks |
Arrays start at 1; unquoted variables do not split; scripts for Bash often break |
| fish | Friendly interactive shell | Autosuggestions and highlighting out of the box, clean syntax | Not POSIX: set x 1, end instead of fi; Bash scripts do not run in it |
| ksh93 | Commercial Unix, origin of many Bash features | Fast, strong scripting, floating-point arithmetic | Less common on Linux |
| BusyBox ash | Alpine Linux, containers, routers | Tiny; close to dash | Limited builtins and tool options |
| PowerShell, nushell, xonsh | Object or Python-flavored shells | Structured data pipelines | Different model altogether |
Interactive features versus scripting
For daily typing, features that matter are completion, syntax highlighting, history search and prompts. fish gives the most without configuration, zsh gives the most with configuration, and Bash gives enough with ~/.inputrc and bash-completion.
For scripts, choose by where the script runs:
- Bash: the sensible default for scripts you control. Use
#!/usr/bin/env bash. - POSIX sh (dash, ash): installers, init scripts, container entrypoints on minimal images, and anything shipped to unknown machines. See POSIX sh vs Bash.
- zsh and fish: fine for personal automation in your own shell, rarely for scripts others will run.
A rule many teams follow: interactive shell by taste, scripts in Bash or POSIX sh, and anything beyond a couple of hundred lines in a real language such as Python.
Usage notes
- Change your login shell with
chsh -s /usr/bin/zsh. The shell must be listed in/etc/shells. Changing it does not change/bin/shor script behavior. - Switching on the fly: typing
zshorfishstarts a nested shell;exitreturns.exec zshreplaces the current shell. - Speed: dash starts several times faster than Bash, which is why Debian made it
/bin/sh: boot scripts start thousands of shells. In loops the difference is small; the cost is in process creation. - Word splitting differs:
for f in $filessplits in Bash and dash but not in zsh, unlesssetopt sh_word_split. - Arrays: Bash indexes from 0, zsh from 1 by default, fish lists from 1 too. Never port array code without checking.
- Startup files differ per shell (
.bashrc,.zshrc,~/.config/fish/config.fish); see Startup files. - Test scripts against the shell named in the shebang, and keep
shellcheck -s shor-s bashin your workflow so it checks the right dialect. - Which is "best"? There is no winner; they optimize different things. Bash is the safest common denominator for Linux work.