$linuxjunkies
>

zsh(1)

Zsh is an interactive login shell and command interpreter for Unix systems with advanced scripting features and customization.

UbuntuDebianFedoraArch

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

FlagWhat it does
-iForce interactive shell mode, even if connected to a pipe or file
-sRead commands from standard input (for scripts)
-c STRINGExecute the command string and exit
-lAct as a login shell, reading login startup files
-nParse commands without executing them (syntax check)
-xPrint commands and their arguments as executed (debug mode)
-dPush directory onto stack for pushd/popd operations
-DTreat arguments as substitutions in FILE rather than options
--versionDisplay zsh version and exit
--helpDisplay help message and exit

Examples

Start an interactive zsh shell

zsh

Execute 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 arg2

Check a script for syntax errors without executing it

zsh -n script.sh

Execute 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/zsh

Start zsh as a login shell, reading ~/.zprofile and ~/.zshrc

zsh -l

Reload zsh configuration in the current interactive session

zsh -i -c 'source ~/.zshrc && exec zsh'