Zsh
Z Shell
Feature-rich shell with excellent tab completion and plugin ecosystem
Overview
Zsh (Z Shell) is a powerful shell that combines features from bash, ksh, and tcsh. Since macOS Catalina, it has been the default shell on macOS. Zsh is known for its excellent interactive features, extensive customization options, and the popular Oh My Zsh framework.
Quick Facts
| Full Name | Z Shell |
| Category | Modern |
| POSIX Compliant | Yes |
| Config File | .zshrc |
| Default On | macOS (Catalina and later), Kali Linux |
| First Release | 1990 |
Who Should Use Zsh?
- Power users - Advanced tab completion and globbing
- macOS users - Default shell since Catalina
- Customization enthusiasts - Themes and plugins via Oh My Zsh
- Developers - Git integration and productivity features
Installation
Install and configure Zsh.
# Install on macOS (pre-installed on Catalina+)
brew install zsh
# Install on Debian/Ubuntu
sudo apt install zsh
# Install on Fedora
sudo dnf install zsh
# Set as default shell
chsh -s $(which zsh)
# Install Oh My Zsh (optional but recommended)
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"Basic Usage
Zsh-specific features and syntax.
# Extended globbing
ls **/*.txt # Recursive glob
ls *(.) # Only files
ls *(/) # Only directories
# Array slicing
arr=(a b c d e)
echo $arr[2,4] # b c d
# Parameter expansion
name="hello"
echo ${(U)name} # HELLO (uppercase)
echo ${(C)name} # Hello (capitalize)
# Spelling correction
setopt CORRECT
# Zsh will suggest corrections for typosConfiguration
Zsh configuration and customization.
# ~/.zshrc configuration
# Oh My Zsh settings
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="robbyrussell"
plugins=(git docker kubectl)
source $ZSH/oh-my-zsh.sh
# Custom prompt (without Oh My Zsh)
PROMPT='%F{green}%n@%m%f:%F{blue}%~%f$ '
# Enable features
setopt AUTO_CD # cd by typing directory name
setopt HIST_IGNORE_DUPS # Ignore duplicate history
setopt SHARE_HISTORY # Share history between sessionsKey Features
Advanced Tab Completion
Context-aware completion with descriptions and menus
Extended Globbing
Powerful pattern matching like **/*.txt for recursive search
Oh My Zsh
Huge ecosystem of themes and plugins
Spelling Correction
Automatic correction suggestions for typos
FAQ
Should I use Oh My Zsh?
Oh My Zsh is great for beginners and provides easy access to themes and plugins. However, it can slow down shell startup. Consider lightweight alternatives like zinit for better performance.
Is Zsh compatible with Bash scripts?
Zsh is largely compatible with Bash scripts, but there are differences. Use "emulate bash" in Zsh or add "#!/bin/bash" shebang to ensure Bash execution.
Summary
Key takeaways for Zsh:
- Default shell on macOS with excellent interactive features
- Advanced tab completion and globbing
- Rich plugin ecosystem via Oh My Zsh
- POSIX compatible with many extensions
Official Documentation
For authoritative information, refer to the official documentation:
Related Articles
Bash - GNU Bourne-Again Shell
The most widely used shell on Linux systems with powerful scripting capabilities
Fish - Friendly Interactive Shell
User-friendly shell with syntax highlighting and autosuggestions out of the box
Sh - Bourne Shell
The original Unix shell and POSIX standard shell