zsh(1)
Zsh is an interactive login shell and command interpreter for Unix systems with advanced scripting features and customization.
Synopsis
zsh [OPTION]... [FILE] [ARGUMENT]...Description
Zsh (Z shell) is a powerful shell that combines features from bash, ksh, and tcsh. It provides advanced tab completion, glob patterns, and extensive customization through configuration files. Zsh is commonly used as both an interactive shell and a scripting interpreter.
When invoked as an interactive shell, zsh reads startup files in order: /etc/zsh/zshenv, ~/.zshenv, /etc/zsh/zprofile (login shells), ~/.zprofile (login shells), /etc/zsh/zshrc, and ~/.zshrc. Scripts are executed in non-interactive mode, skipping most startup files.
Common options
| Flag | What it does |
|---|---|
-i | Force interactive shell mode, even if connected to a pipe or file |
-s | Read commands from standard input (for scripts) |
-c STRING | Execute the command string and exit |
-l | Act as a login shell, reading login startup files |
-n | Parse commands without executing them (syntax check) |
-x | Print commands and their arguments as executed (debug mode) |
-d | Push directory onto stack for pushd/popd operations |
-D | Treat arguments as substitutions in FILE rather than options |
--version | Display zsh version and exit |
--help | Display help message and exit |
Examples
Start an interactive zsh shell
zshExecute a single command in zsh and exit, displaying the shell version
zsh -c 'echo $ZSH_VERSION'Run a zsh script with positional arguments
zsh script.sh arg1 arg2Check a script for syntax errors without executing it
zsh -n script.shExecute a command with debug output showing each step
zsh -x -c 'for i in 1 2 3; do echo $i; done'Change default login shell to zsh for the current user
chsh -s /bin/zshStart zsh as a login shell, reading ~/.zprofile and ~/.zshrc
zsh -lReload zsh configuration in the current interactive session
zsh -i -c 'source ~/.zshrc && exec zsh'