Post

πŸ’» 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.

CommandshBashZshNotes
. (dot)βœ“βœ“βœ“Sources a script file
: (colon)βœ“βœ“βœ“Null command (does nothing but returns success)
[βœ“βœ“βœ“Condition evaluation (alias for test)
aliasLimitedβœ“βœ“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
unaliasLimitedβœ“βœ“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

  1. Core Commands:
    • sh: Provides minimalist but essential commands
    • Bash: Extends sh with interactive features
    • Zsh: Further extends with advanced customization
  2. Variable Handling:
    • sh: Basic variable support
    • Bash: Added arrays and better variable manipulation
    • Zsh: Added specialized variable types (integer, float)
  3. Command Completion:
    • sh: None or minimal
    • Bash: Programmable completion system
    • Zsh: Advanced, context-aware completion system
  4. 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.