Bash vs Zsh: Technical Comparison

Core Differences

Feature Bash Zsh
Initial Release 1989 1990
Default Prompt $ %
Configuration File ~/.bashrc ~/.zshrc
Globbing Basic pattern matching Extended patterns + qualifiers

Key Technical Divergences

1. Pattern Matching

# Bash (basic glob)
ls *.txt

# Zsh (qualified glob)
ls **/*.txt(.)  # Only regular files
ls *.txt(om)    # Ordered by modification time

2. Array Handling

# Bash (0-indexed)
arr=(a b c)
echo ${arr[0]}  # a

# Zsh (1-indexed)
arr=(a b c)
echo $arr[1]    # a

3. Error Handling

# Bash continues script by default
false
echo $?  # 1

# Zsh (can enable strict mode)
set -e
false && echo "OK"  # Script terminates

4. Parameter Expansion

# Zsh-specific modifiers
file="file.txt"
echo ${file:r}   # "file" (remove extension)
echo ${file:e}   # "txt" (get extension)

Performance Characteristics

  • Startup Time: Zsh ~30-50ms slower (with frameworks)
  • Memory Usage: Comparable for basic operations
  • Plugin Systems: Zsh has native module support

Compatibility Matrix

Feature Bash Zsh
POSIX Compliance High Medium
sh Emulation Native Needs emulate sh
Associative Arrays 4.0+ 5.0+
  • Choose Bash:
    • System scripts (especially /bin/sh)
    • POSIX compliance requirements
    • Minimal environment setups
  • Choose Zsh:
    • Interactive development
    • Complex command-line workflows
    • Customizable environments (Oh My Zsh)