Zsh Shell with power globbing
Light · Postcard
102 × 152 mm · PDF
Dark · Postcard
102 × 152 mm · PDF
Ink saver · Postcard
102 × 152 mm · PDF
Light · A4 landscape
297 × 210 mm · PDF
Dark · A4 landscape
297 × 210 mm · PDF
Ink saver · A4 landscape
297 × 210 mm · PDF
Light · A3 landscape
420 × 297 mm · PDF
Dark · A3 landscape
420 × 297 mm · PDF
Ink saver · A3 landscape
420 × 297 mm · PDF
Start here
ls **/*.mdls *(.)ls *(om[1,5])${var:u}print -l $pathsetopt auto_cd!!autoload -Uz compinit
Concepts
- History !! and !$
- Aliases global and suffix too
- Expansion ${...}, $(...), globs
- Command status in $?
Globbing
ls **/*.<ext>
ls *(/)ls *(.)ls *(@)ls *(*)ls *(om[1,5])ls *(Lm+10)ls *(mh-1)ls *(.N)ls ^*.logls *.(jpg|png)Parameter Expansion
${var:-<default>}
${var:u}${var:l}${var:t}${var:h}${var:r}${var:e}${#var}${var/<old>/<new>}
${var//<old>/<new>}
${var#<pat>}
${var%<pat>}
${(s:,:)var}Arrays & Maps
arr=(a b c)$arr[1]$arr[-1]$arr[2,3]arr+=(<item>)
${#arr}${arr[@]}typeset -A <map>
map=(k1 v1 k2 v2)
print -l $arrtypeset -U pathpath=(~/bin $path)
History
!!sudo !!!$!^!*!<n>!<str>^<old>^<new>
historyCtrl+RUp / DownAlt+.setopt share_history
setopt hist_ignore_all_dups
Options
setopt <option>
unsetopt <option>
setoptsetopt auto_cdsetopt auto_pushd
setopt extended_glob
setopt interactive_comments
HISTSIZE=<n> SAVEHIST=<n>
HISTFILE=~/.zsh_history
Prompt, Aliases & Completion
PROMPT='%n@%m %~ %# '
RPROMPT='%*'
alias <name>='<cmd>'
autoload -Uz compinit && compinit
zstyle ':completion:*' menu select
bindkey -eTab Tabsource ~/.zshrcDirectories & Functions
cd -<n>dirs -v<name>() { ... }
whence -v <name>
noglob <cmd>
zsh -n <file>
Differences from Bash
| Topic | Bash | Zsh |
|---|---|---|
| Unquoted $var | word-split | not split |
| Array start | index 0 | index 1 |
| No glob match | passes pattern | error |
| Prompt read | read -p | read '?txt ' |
| Config file | ~/.bashrc | ~/.zshrc |
| Ignore case | nocasematch | (#i) |
read -r '?Name: ' <var>
[[ $a == <pat> ]]
(( a < b ))for i in {1..5}; do ...
Recipes
autoload -Uz compinit && compinitsetopt auto_cd share_historyHISTFILE=~/.zsh_history SAVEHIST=50000typeset -U path; path=(~/bin $path)
ls -l **/*.log(.Lm+10mw+4)# review the list, thenrm -- **/*.log(.Lm+10mw+4)
autoload -Uz zmvzmv '(*).jpeg' '$1.jpg'
f=/srv/app/report.tar.gzprint ${f:h} # /srv/appprint ${f:t} # report.tar.gzprint ${f:r} # /srv/app/report.tar



