ZSHMISC(1) General Commands Manual ZSHMISC(1) (NAME) zshmisc - (SIMPLE COMMANDS & PIPELINES) (blank-separated) . zshparam(1) . . . . echo foo . (pipeline) <<|>> <<|&>> . <<|>> . <<|&>> <<2>&1 |>> . <> . echo foo | sed 's/foo/bar/' (<> ) . <> (coprocess) . <<>&p>> <<<&p>> <> <> . <> <> . (job control) . (sublist) <<&&>> <<||>> . <<&&>> ( ). <<||>> ( ). . . dmesg | grep panic && print yes grep . print ( ). (list) <<;>> <<&>> <<&|>> <<&!>> . <<(...)>> <<{...}>> . <<;>> . <<&>> <<&|>> <<&!>> ( ). . <<>> . . (PRECOMMAND MODIFIERS) (precommand modifier) . (builtin) nocorrect . - <<->> argv[0] . builtin . command [ -pvV ] . POSIX_BUILTINS . -p $path . -v command whence -V whence -v . exec [ -cl ] [ -a argv0 ] . (fork) . TRAPEXIT zlogout . . -c . -l - - argv[0] . -a . -a argv[0] ( ) ARGV0 . nocorrect . (parse) . . noglob (globbing) ..SH " (COMPLEX COMMANDS)" zsh : if list then list [ elif list then list ] ... [ else list ] fi list if list then . list elif list then . list elif list else . for name ... [ in word ... ] term do list done word name list . `in word' word . term ; word `in word' . name word . N name N (word) . name word . word name . in name . for (( [expr1] ; [expr2] ; [expr3] )) do list done expr1 ( `Arithmetic Evaluation' ). expr2 list expr3 . 1 . while list do list done list while list do . until list do list done list until list do . repeat word do list done word n . list n . repeat . `enable -r repeat' . case word in [ [(] pattern [ | pattern ] ... ) list (;;|;&|;|) ] ... esac list pattern word ( ) . . `Filename Generation' . SH_GLOB (whitespace) . . SH_GLOB case ( ). list ;; ;& . ;; ;& ;| esac . list ;| pattern list ;; ;& ;| . word pattern word . select name [ in word ... term ] do list done term ; word . word . in word . PROMPT3 . word name word . . name null . REPLY . list break (end-of-file) . ( list ) list (subshell) . trap list POSIXTRAPS . { list } list . { try-list } always { always-list } try-list . break continue try-list always-list . try-list break continue always-list . <> <> . always always . <<>> . always-list . if try-list always-list ${*foo*} always-list . TRY_BLOCK_ERROR . always-list -1 . always-list try-list 1 0 . TRY_BLOCK_ERROR always-list 0 try-list always-list . try-list ( always ). TRY_BLOCK_ERROR always-list $? try-list . TRY_BLOCK_ERROR . . . { # code which may cause an error } always { # This code is executed regardless of the error. (( TRY_BLOCK_ERROR = 0 )) } # The error condition has been reset. try return exit try-list always-list . EXIT . return try-list break continue always-list . function [ -T ] word ... [ () ] [ term ] { list } word ... () [ term ] { list } word ... () [ term ] command term ; . word . word word . list { } . `Functions' . function : -T (tracing) functions -T . -f typeset zshbuiltins(1) ..PP SH_GLOB word (globbing pattern) . (redirection) func() { ... } 2>&1 . (scope) . time [ pipeline ] pipeline TIMEFMT . pipeline . [[ exp ]] exp . exp `Conditional Expressions' . (ALTERNATE FORMS FOR COMPLEX COMMANDS) zsh . . sublist `{ list }' SHORT_LOOPS . if while until `[[ ... ]]' `(( ... ))' . for repeat case select ( sublist SHORT_LOOPS) . SHORT_REPEAT repeat . if list { list } [ elif list { list } ] ... [ else { list } ] if. if [[ -o ignorebraces ]] { print yes } if true { # Does not work! print yes } . if list sublist if . list . for name ... ( word ... ) sublist for. for name ... [ in word ... ] term sublist term ; . for. for (( [expr1] ; [expr2] ; [expr3] )) sublist for. foreach name ... ( word ... ) list end for. while list { list } while. list . until list { list } until. list . repeat word sublist repeat . case word { [ [(] pattern [ | pattern ] ... ) list (;;|;&|;|) ] ... } case. select name [ in word ... term ] sublist term ; . select. function word ... [ () ] [ term ] sublist function . (RESERVED WORDS) disable -r : do done esac then elif else fi for case if while function repeat time until select coproc nocorrect foreach end ! [[ { } declare export float integer local readonly typeset IGNORE_BRACES IGNORE_CLOSE_BRACES `}' ..SH " (ERRORS)" : (abort) . zsh CONTINUE_ON_ERROR . : o o set o o typeset local declare export integer float o (continue break) o o RESTRICTED o pipe (pipeline) o multio o (autoload) o o glob ( glob qualifiers) o (file generation) BAD_PATTERN o case o NOMATCH o multio o o o (read-only) o o o o $'...' POSIX_BUILTINS POSIX . (COMMENTS) INTERACTIVE_COMMENTS histchars ( `#') (newline) . (ALIASING) (alias) . ( ) (global) . . sh `word () ...' (word) ALIAS_FUNC_DEF . alias -g . : o glob o ( ) o o o (case do else ) o `(' `)' glob (history expansion) . foo \foo . \foo . unalias : % alias -g foo=bar % unalias foo unalias: no such hash table element: bar % unalias \foo % POSIX_ALIASES . alias . (completion) 'foo . . ( aliases THE ZSH/PARAMETER MODULE zshmodules(1) ). POSIX_ALIASES . = = = . <<((>> <<(>> . && \&& \& & . \<< \>| . : alias echobar='echo bar'; echobar echobar . echobar . <> <<.>> . . (QUOTING) <<\>> ( ). <<\>> . <<$'>> <<'>> print . <<'>> <<\'>> . ('') <<$>> . RC_QUOTES . print '''' RC_QUOTES . ("") <<\>> <<\>> <<`>> <<">> <<$>> $histchars ( <>) . (REDIRECTION) & /dev/null . / . . word digit . word . < word word . . <> word word . . > word word . . CLOBBER . >| word >! word > CLOBBER . >> word word . CLOBBER APPEND_CREATE . >>| word >>! word >> CLOBBER APPEND_CREATE . <<[-] word word (end-of-file) . word . here-document . word <<\>> . <<\>> <<\>> <<$>> <<`>> word <<\>> . word . word . ( .) $'...' . <<- word . <<< word word . here-string . word here-document word . . <& number >& number / number ( dup2(2) ). <& - >& - / . <& p >& p / / / . >& word &> word ( <<>& word>> <<&>>> .) ( ) <<> word>> . multios <<> word 2>&1>> ( )..TP >&| word >&! word &>| word &>! word ( ) `>| word' . >>& word &>> word ( ) `>> word' . >>&| word >>&! word &>>| word &>>! word ( ) `>>| word' . 0 1. . (file descriptor, file) . : ... 1>fname 2>&1 1 fname . 2 1 ( fname) . 2 ( 1 ) 1 fname . `|&' Simple Commands & Pipelines zshmisc(1) `2>&1 |' . (Process Substitution) `<(list)' `=(list)' `>(list)' . word `>(list)' list . Process Substitution zshexpn(1) . (OPENING FILE DESCRIPTORS USING PARAMETERS) IGNORE_BRACES : . 10 . . : ... {myfd}>&1 (duplicate) 1 myfd 10 . >&$myfd . (subshells) (forked) . {varid}>&- {myfd}>&- . varid . (readonly) . param <&$param >&$param . CLOBBER (unset ) . (unset ) . . exec . . : integer myfd exec {myfd}>~/logs/mylogfile.txt print This is a log message. >&$myfd exec {myfd}>&- >&$myfd . ..SH "MULTIOS" (file descriptor) MULTIOS ( ) (pipe) tee . : date >foo >bar `foo' `bar' . date >foo | cat `foo' pipe cat . multio . . MULTIOS . >&1 : date >&1 >output >&1 tee . : date >output >&1 >&1 output . . MULTIOS (globbing) . : > * ( ) (truncate) . ( MULTIOS `*' .) : echo exit 0 >> *.sh MULTIOS . : cat cat . sort sort `cat foo fubar | sort' . >&$myfd . cat bar | sort `cat bar foo | sort' ( ). MULTIOS (unset) . echo Hello > bar > baz MULTIOS `bar' (truncate) `Hello' `baz' . multio . : cat file >file1 >file2 cat file1 file2 `cat' file1 file2 ( file ). multio (fork) cat multio . file1 file2 . cat (job) : { cat file } >file >file2 {...} . zsh . NULLCMD CSH_NULLCMD . csh CSH_NULLCMD csh . SH_NULLCMD `:' . sh ksh . NULLCMD . NULLCMD READNULLCMD . NULLCMD `cat' READNULLCMD `more'' . < file file . NULLCMD READNULLCMD . (COMMAND EXECUTION) () . `Functions' . . $path . : . 127 . `command not found: cmd' . 126 . execve(2) . . /bin/sh (spawn) . `#!' . . command_not_found_handler . . (subshell) (forked) . (FUNCTIONS) function `funcname ()' . . (Alias) . . ( `Command Execution' .) . (trap) EXIT . return . functions . unfunction . (AUTOLOADING FUNCTIONS) autoload ( `functions -u' `typeset -fu') undefined () . . fpath . : fpath=(~/myfuncs $fpath) autoload myfunc1 myfunc2 ... autoload -U . zsh . zcompile -U .zwc . element fpath : element.zwc zcompile element . . . element .zwc ( ) element element . `/usr/local/funcs.zwc' fpath . element/function.zwc zcompile function . function . element/function zsh function . : fpath fpath fpath . KSH_AUTOLOAD . . . ( `funcname() {...}' ) . . . ( ) ( ) . func : func() { print This is func; } print func is initialized `func; func' KSH_AUTOLOAD `This is func' . KSH_AUTOLOAD . fpath `autoload -X' . : myfunc() { autoload -X } myfunc args... .PP unfunction myfunc # if myfunc was defined autoload myfunc myfunc args... functions `builtin autoload -X' (autoloaded) . eval "$(functions)" . `# undefined' . myfunc myfunc : autoload +X myfunc (ANONYMOUS FUNCTIONS) <<>> (`anonymous') . : `()' `function' . . `(anon)' . ( $0) . : `else' `fi' (newline) - . ( ). . (scope) . (start-up files) . variable=outside function { local variable=inside print "I am $variable with arguments $*" } this and that print "I am $variable" : I am inside with arguments this and that I am outside (expand) `name=; function $name { ... }' . . (SPECIAL FUNCTIONS) . (Hook Functions) `_functions' . (context) $? . $chpwd_functions `mychpwd' `chpwd_save_dirstack' `chpwd' `mychpwd' `chpwd_save_dirstack' . . (hook function) . . precmd periodic ( ). chpwd . periodic PERIOD $PERIOD (prompt) . periodic_functions . . precmd . (precommand) (job) . preexec . ( ) . ( ) : ( ) . zshaddhistory . ( ). ( ) . . . `fc -p ...' HISTFILE . : . INC_APPEND_HISTORY SHARE_HISTORY . . . zshaddhistory() { print -sr -- ${1%%$'\n'} fc -p .zsh_local_history } zshexit . (subshells) exec . TRAPEXIT . (hook) . TRAPNAL (non-null) SIGNAL ( NAL kill ) . . (null) SIGNAL . . . . . SIGINT . TRAPINT() { print "Caught SIGINT, aborting." return $(( 128 + $1 )) } TRAPZERR TRAPDEBUG TRAPEXIT . TRAPDEBUG DEBUG_BEFORE_CMD ( ) . trap zshbuiltins(1) . TRAPEXIT . $? . TRAPZERR . `&&' `||' . TRAPERR SIGERR ( ) TRAPZERR . `TRAP' trap : . . TRAPNAL() { # code } (<< >>) trap ' # code ' NAL (<< >>) : o . o (return) . o zsh (subshells) POSIX . (JOBS) MONITOR (job) (pipeline) . jobs . `&' : [1] 1234 ( ) (PID) . `&|' `&!' (disown) . . ^Z (-Z) TSTP : susp stty . (`suspended') (prompt) . bg fg . ^Z . . (fork) . . fg . . Zsh . disown : (disown) . . if for . `stty tostop' . tty . fg wait zsh tty . ( ) `kill -CONT' bg . . : %number . %string string . %?string string . %% . %+ `%%'. %- . . . NOTIFY . ..PP (monitor mode) (trap) CHLD . <>. jobs . HUP SIGHUP . nohup(1) disown. (SIGNALS) INT QUIT <<&>> MONITOR . QUIT . ( TRAPNAL <> ). exit ERR_EXIT . (process substitution) PROCESS SUBSTITUTION zshexpn(1) multios MULTIOS zshmisc(1) . (ARITHMETIC EVALUATION) let $((...)) . . <> . <> . let . : <<((>> <<))>> let . <<((...))>> <> . . (( val = 2 + 1 )) let "val = 2 + 1" val . . <<0x>> <<0X>> <<0b>> <<0B>> . <> base n ( <<16#ff>> ). base# . <<[base]n>> . <> (<<_>>) . 1_000_000 0xffff_ffff 1000000 0xffffffff . <<[#base]>> <<[#16]>> . . <<-i base>> typeset . . . : typeset -i 16 y print $(( [#8] x = 32, y = 32 )) print $x $y <<8#40>> <<8#40 16#20>> y x ( ) . base ( ). . . : setopt cbases print $(( [#16_4] 65536 ** 2 )) <<0x1_0000_0000>> . . zmodload zsh/mathfunc print $(( [#_] sqrt(1e7) )) <<3_162.277_660_168_379_5>> ( ). C_BASES C <<0xFF>> <<16#FF>>. OCTAL_ZEROES ( ) <<8#77>> <<077>> . . <<[#base]>> . # <<[##16]>> . ( ) . e E . ( ) . C . ( ): + - ! ~ ++ -- / NOT {}{} << >> & AND ^ XOR | OR ** * / % () + - < > <= >= == != .TP && AND || ^^ OR XOR ? : = += -= *= /= %= &= ^= |= <<= >>= &&= ||= ^^= **= , `&&' `||' `&&=' `||=' (short-circuiting) . AND OR XOR . C_PRECEDENCES ( ) : + - ! ~ ++ -- / NOT {}{} ** * / % (modulus) + - << >> < > <= >= == != & AND ^ XOR | OR && AND ^^ XOR || OR ? : = += -= *= /= %= &= ^= |= <<= >>= &&= ||= ^^= **= , `-3**2' `9' `-9'. : `-(3**2)'. . `func(args)' args . zsh/mathfunc zmodload . `##x' x `a' `^A' `\M-\C-x' `#name' name . (locale) MULTIBYTE . `$#name' name . `#\' `##' . . ((val2 = val1 * 2)) $val1 val2 . integer . . . float typeset . `${float}' `$((float))' . . (`&' `|' `^' `<<' `>>' ) `~' . ( ) zsh . 6/8 (truncated) . FORCE_FLOAT . (scalar) . integer float (scope) . . for (( f = 0; f < 1; f += 0.1 )); do # use $f done f `f += 0.1' . `f = 0.0' . . [[ . : -a file file . -b file file . -c file file . -d file file . -e file file . -f file file . -g file file setgid . -h file file . -k file file sticky . -n string string . -o option option . option . ( `Specifying Options' .) option POSIX_BUILTINS . . -p file file FIFO ( ) . -r file file . -s file file . -t fd fd . (: fd ) -u file file setuid . -v varname varname . -w file file . -x file file . file . -z string string . -L file file . -O file file (effective UID) . -G file file (effective GID) . -S file file . -N file file . file1 -nt file2 file1 file2 . file1 -ot file2 file1 file2 . file1 -ef file2 file1 file2 . string = pattern string == pattern string pattern . . `=' ( test [ ) `==' . string != pattern string pattern . string =~ regexp string regexp . RE_MATCH_PCRE regexp PCRE zsh/pcre POSIX zsh/regex . . BASH_REMATCH MATCH MBEGIN MEND string string var `${var[$MBEGIN,$MEND]}' `$MATCH' . KSH_ARRAYS . match mbegin mend string . . `a short string' `s(...)t' ( KSH_ARRAYS ) MATCH MBEGIN MEND `short' 3 7 match mbegin mend `hor' `4' `6' . BASH_REMATCH BASH_REMATCH . string1 < string2 string1 ASCII string2 . string1 > string2 string1 ASCII string2 . exp1 -eq exp2 exp1 exp2 . ((...)) `ARITHMETIC EVALUATION' . exp1 -ne exp2 exp1 exp2 . exp1 -lt exp2 exp1 exp2 . exp1 -gt exp2 exp1 exp2 . exp1 -le exp2 exp1 exp2 . exp1 -ge exp2 exp1 exp2 . ( exp ) exp . ! exp exp . exp1 && exp2 exp1 exp2 . exp1 || exp2 exp1 exp2 . . [[ $var ]] [[ -n $var ]] . ..PP file string pattern (double quotes) . (Filename generation) . EXTENDED_GLOB glob (#q) . glob <> . . [[ . [ test globbing . test . [[ -n file*(#qN) ]] <> . N . pattern zshexpn(1) <> glob . file <> n (descriptor) n /dev/fd . exp $((...)) . : [[ ( -f foo || -f bar ) && $report = y* ]] && print File exists. foo bar report <> <> . (EXPANSION OF PROMPT SEQUENCES) . -P print . PROMPT_SUBST . zshexpn(1) . . PROMPT_BANG <> . <> <> . PROMPT_PERCENT <<%>> . <<%>> . . (SIMPLE PROMPT ESCAPES) (Special characters) %% <<%>>. %) <<)>>. (Login information) %l (tty) <>. <> . %M . %m <<.>>. <<%>> . . %n $USERNAME. %y (tty) <>. <> . %# <<#>> <<%>>. <<%(!.#.%%)>>. <<>> ( ) (effective user ID) POSIX.1e (Effective) (Inheritable) . %? (prompt). %_ (parser) ( <> <>) . . PS2 PS4 XTRACE . %^ . <<%_>> . RPS2 . %d %/ . <<%>> . %-1d . %~ %d %/ $HOME <<~>> . <<~>> Dynamic Static named directories zshexpn(1) . %e (sourced) eval. %N . $PS4 . %h %! (history) . %i %N . $PS4 . %I %x . %i . %j (jobs). %L $SHLVL. %N zsh ( ). $0 . <<%>> . . %x . %N eval . %c %. %C . <<%>> . <<%C>> . %c %C %1~ %1/ . (Date and time) %D yy-mm-dd. %T . %t %@ am/pm. %* . %w day-dd. %W mm/dd/yy. %D{string} string strftime . strftime(3) . zsh : %f %K %L POSIX gettimeofday %. (epoch) . % %6. %9. . ( clock_gettime ). <<%D{%H:%M:%S.%.}>> . %N %9. . <<->> % d f H k l m M S y <<->> strftime(3) . ( ) strftime(3) . %B (%b) () (boldface). %E . %U (%u) () (underline). %S (%s) () (standout). %F (%f) () . : %F %F{red}. fg zle_highlight (Character Highlighting) zshzle(1) . . %K (%k) () . %F %f . %{...%} (escape sequence) . . . % { %G . %G %{...%} <> . . %{...%} %G . <<%>> <> . %{seq%2G%} seq . %G %G . . %{...%} . (CONDITIONAL SUBSTRINGS IN PROMPTS) %v psvar. <<%>> . . %(x.true-text.false-text) . x <<>> <<>> . true-text %-escape. <<)>> false-text <<%)>> . true-text false-text . n . -1 <> . x : ! (privileges) . # uid n . ? n . _ n . C / n / . c . ~ n / . D n ( = ). d n . e n . g gid n . j n . L SHLVL n . l n . n abs(n) ( RPROMPT). S SECONDS n . T n . t n . v psvar n . V n psvar . w n ( = ). %string> %[xstring] . <<%xstringx>> x <<<>> <<>>> . string . <<[>> . . . n ( RPROMPT) . <<<>> <<>>> . <> <<%8<..<%/>> <<..e/pike>> . (<<<>> <<>>> <<]>>) <<\>> print -P print : <> . string ..PP `%(' ( `%(' ) . ( `%<<') . `%10<...<%~%<<%# ' `%' `#' . `%<<' . `%-0<<' `%<<' . ( ) . . `%-n(l.true-text.false-text)' n . zsh 5.9.2 July 12, 2026 ZSHMISC(1)