π» sh vs Zsh vs Bash Built-in Commands Comparison
π» sh vs Zsh vs Bash Built-in Commands Comparison
This table compares the built-in commands available in the original Bourne Shell (sh), Z Shell (Zsh), and Bourne Again Shell (Bash). Commands are organized alphabetically with notes on key differences.
| Command | sh | Bash | Zsh | Notes |
|---|---|---|---|---|
. (dot) | β | β | β | Sources a script file |
: (colon) | β | β | β | Null command (does nothing but returns success) |
[ | β | β | β | Condition evaluation (alias for test) |
alias | Limited | β | β | Create command aliases; limited in original sh |
autoload | β | β | β | Zsh-specific: load functions on demand |
bg | β | β | β | Resume jobs in the background |
bind | β | β | β | Bash-specific: display or set readline key bindings |
bindkey | β | β | β | Zsh-specific: display or set key bindings |
break | β | β | β | Exit from loops |
builtin | β | β | β | Execute built-in commands directly |
caller | β | β | β | Bash-specific: return context of subroutine call |
cd | β | β | β | Change directory |
command | β | β | β | Execute command bypassing any aliases |
compdef | β | β | β | Zsh-specific: define completion functions |
compgen | β | β | β | Bash-specific: generate possible completions |
complete | β | β | β | Bash-specific: specify how to complete arguments |
compopt | β | β | β | Bash-specific: modify completion options |
compsys | β | β | β | Zsh-specific: completion system initialization |
continue | β | β | β | Skip to next iteration of a loop |
declare | β | β | β | Declare variables with attributes |
dirs | β | β | β | Display directory stack |
disown | β | β | β | Remove jobs from current shell |
echo | β | β | β | Display arguments as text |
enable | β | β | β | Bash-specific: enable/disable shell built-ins |
eval | β | β | β | Evaluate arguments as shell commands |
exec | β | β | β | Replace current process with specified command |
exit | β | β | β | Exit the shell |
export | β | β | β | Set environment variables |
false | β | β | β | Return a failure status |
fc | β | β | β | Fix command (history editing) |
fg | β | β | β | Resume job in foreground |
float | β | β | β | Zsh-specific: declare floating-point variables |
function | β | β | β | Define a function (sh uses different syntax) |
getopts | β | β | β | Process command-line options |
hash | β | β | β | Remember command locations |
help | β | β | β | Bash-specific: display help for built-ins |
history | β | β | β | Display command history |
if | β | β | β | Conditional statement |
integer | β | β | β | Zsh-specific: declare integer variables |
jobs | β | β | β | List active jobs |
kill | β | β | β | Send signals to processes |
let | β | β | β | Evaluate arithmetic expressions |
local | β | β | β | Declare local variables |
logout | β | β | β | Exit a login shell |
mapfile | β | β | β | Bash-specific: read lines into array variable |
popd | β | β | β | Remove directories from directory stack |
print | β | β | β | Zsh-specific: more versatile version of echo |
printf | β | β | β | Format and print data |
pushd | β | β | β | Add directories to directory stack |
pwd | β | β | β | Print working directory |
read | β | β | β | Read from stdin into variables |
readarray | β | β | β | Bash-specific: read lines into array variable |
readonly | β | β | β | Mark variables as read-only |
rehash | β | β | β | Zsh-specific: rebuild command hash table |
return | β | β | β | Return from a function |
set | β | β | β | Set/unset shell options and positional parameters |
setopt | β | β | β | Zsh-specific: set shell options |
shift | β | β | β | Shift positional parameters |
shopt | β | β | β | Bash-specific: set/unset shell options |
source | β | β | β | Execute commands from file (sh only has .) |
suspend | β | β | β | Suspend shell execution |
test | β | β | β | Evaluate conditional expression |
times | β | β | β | Display process times |
trap | β | β | β | Trap signals and events |
true | β | β | β | Return a successful status |
type | β | β | β | Display command type |
typeset | β | β | β | Declare variables and their attributes |
ulimit | β | β | β | Set resource limits |
umask | β | β | β | Set file creation mask |
unalias | Limited | β | β | Remove command aliases |
unfunction | β | β | β | Zsh-specific: remove function definitions |
unhash | β | β | β | Zsh-specific: remove command from hash table |
unset | β | β | β | Remove variables or functions |
unsetopt | β | β | β | Zsh-specific: unset shell options |
wait | β | β | β | Wait for job completion |
whence | β | β | β | Zsh-specific: describe command (similar to type) |
which | β | β | β | Zsh-specific: locate command |
zcompile | β | β | β | Zsh-specific: compile functions/scripts for faster loading |
zformat | β | β | β | Zsh-specific: format strings |
zle | β | β | β | Zsh-specific: zsh line editor commands |
zmodload | β | β | β | Zsh-specific: load zsh modules |
zparseopts | β | β | β | Zsh-specific: parse options |
zpty | β | β | β | Zsh-specific: pseudo terminal handling |
zregexparse | β | β | β | Zsh-specific: parsing based on regular expressions |
zstyle | β | β | β | Zsh-specific: set style for completion system |
Shell Evolution and Feature Comparison
Bourne Shell (sh)
The original Unix shell developed by Stephen Bourne at Bell Labs in 1979:
- Minimalist design with essential shell functionality
- Focus on scripting rather than interactive use
- Limited job control
- No command history
- No command line editing
- Basic built-in commands only
- POSIX-compliant (original reference implementation)
Bash (Bourne Again Shell)
Developed by Brian Fox for the GNU Project in 1989:
- Direct extension of the Bourne shell
- Strong focus on POSIX compliance
- Enhanced scripting capabilities
- Command history and editing
- Job control
- Programmable completion
- Array support
- More advanced parameter expansion
Zsh (Z Shell)
Developed by Paul Falstad in 1990:
- Extended feature set beyond Bash
- Modular design with loadable modules
- Highly customizable
- Advanced pattern matching and globbing
- Theming capabilities
- Spelling correction
- Sophisticated tab completion system
- Floating point arithmetic
- More extensive string handling
- Better interactive features
Key Functional Differences
- Core Commands:
- sh: Provides minimalist but essential commands
- Bash: Extends sh with interactive features
- Zsh: Further extends with advanced customization
- Variable Handling:
- sh: Basic variable support
- Bash: Added arrays and better variable manipulation
- Zsh: Added specialized variable types (integer, float)
- Command Completion:
- sh: None or minimal
- Bash: Programmable completion system
- Zsh: Advanced, context-aware completion system
- Scripting Capabilities:
- sh: Basic scripting support
- Bash: Enhanced scripting with more built-ins
- Zsh: Most extensive scripting capabilities
This post is licensed under CC BY 4.0 by the author.