1ZSHMISC(1)                  General Commands Manual                 ZSHMISC(1)
2
3
4

NAME

6       zshmisc - everything and then some
7

SIMPLE COMMANDS & PIPELINES

9       A  simple  command is a sequence of optional parameter assignments fol‐
10       lowed by  blank-separated  words,  with  optional  redirections  inter‐
11       spersed.  The first word is the command to be executed, and the remain‐
12       ing words, if any, are arguments to the command.  If a command name  is
13       given,  the parameter assignments modify the environment of the command
14       when it is executed.  The value of a simple command is its exit status,
15       or 128 plus the signal number if terminated by a signal.  For example,
16
17              echo foo
18
19       is a simple command with arguments.
20
21       A  pipeline  is  either  a simple command, or a sequence of two or more
22       simple commands where each command is separated from the next by `|' or
23       `|&'.   Where commands are separated by `|', the standard output of the
24       first command is connected to the standard input of the next.  `|&'  is
25       shorthand for `2>&1 |', which connects both the standard output and the
26       standard error of the command to the standard input of the  next.   The
27       value  of a pipeline is the value of the last command, unless the pipe‐
28       line is preceded by `!' in which case the value is the logical  inverse
29       of the value of the last command.  For example,
30
31              echo foo | sed 's/foo/bar/'
32
33       is  a  pipeline,  where  the output (`foo' plus a newline) of the first
34       command will be passed to the input of the second.
35
36       If a pipeline is preceded by `coproc', it is executed as a coprocess; a
37       two-way pipe is established between it and the parent shell.  The shell
38       can read from or write to the coprocess by means of the `>&p' and `<&p'
39       redirection  operators  or  with  `print -p' and `read -p'.  A pipeline
40       cannot be preceded by both `coproc' and `!'.  If job control is active,
41       the coprocess can be treated in other than input and output as an ordi‐
42       nary background job.
43
44       A sublist is either a single pipeline, or a sequence  of  two  or  more
45       pipelines separated by `&&' or `||'.  If two pipelines are separated by
46       `&&', the second pipeline  is  executed  only  if  the  first  succeeds
47       (returns  a  zero  value).  If two pipelines are separated by `||', the
48       second is executed only if the first fails (returns a  nonzero  value).
49       Both  operators  have  equal  precedence and are left associative.  The
50       value of the sublist is the value of the last pipeline  executed.   For
51       example,
52
53              dmesg | grep panic && print yes
54
55       is a sublist consisting of two pipelines, the second just a simple com‐
56       mand which will be executed if and only if the grep command  returns  a
57       zero  value.   If  it does not, the value of the sublist is that return
58       value, else it is the value returned by  the  print  (almost  certainly
59       zero).
60
61       A list is a sequence of zero or more sublists, in which each sublist is
62       terminated by `;', `&', `&|', `&!', or a newline.  This terminator  may
63       optionally  be  omitted from the last sublist in the list when the list
64       appears as a complex command inside `(...)'  or `{...}'.  When  a  sub‐
65       list  is terminated by `;' or newline, the shell waits for it to finish
66       before executing the next sublist.  If a sublist  is  terminated  by  a
67       `&',  `&|',  or `&!', the shell executes the last pipeline in it in the
68       background, and does not wait for it to  finish  (note  the  difference
69       from  other  shells which execute the whole sublist in the background).
70       A backgrounded pipeline returns a status of zero.
71
72       More generally, a list can be seen as a set of any shell commands what‐
73       soever,  including the complex commands below; this is implied wherever
74       the word `list' appears in later descriptions.  For example,  the  com‐
75       mands in a shell function form a special sort of list.
76

PRECOMMAND MODIFIERS

78       A  simple  command may be preceded by a precommand modifier, which will
79       alter how the  command  is  interpreted.   These  modifiers  are  shell
80       builtin  commands  with  the exception of nocorrect which is a reserved
81       word.
82
83       -      The command is executed with a  `-'  prepended  to  its  argv[0]
84              string.
85
86       noglob Filename  generation  (globbing)  is not performed on any of the
87              words.
88
89       nocorrect
90              Spelling correction is not done on any of the words.  This  must
91              appear  before  any  other  precommand modifier, as it is inter‐
92              preted immediately, before any  parsing  is  done.   It  has  no
93              effect in non-interactive shells.
94
95       exec   The command is executed in the parent shell without forking.
96
97       command
98              The command word is taken to be the name of an external command,
99              rather than a shell function or builtin.
100
101       builtin
102              The command word is taken to be the name of a  builtin  command,
103              rather than a shell function or external command.
104

COMPLEX COMMANDS

106       A complex command in zsh is one of the following:
107
108       if list then list [ elif list then list ] ... [ else list ] fi
109              The  if  list is executed, and if it returns a zero exit status,
110              the then list is executed.  Otherwise, the elif list is executed
111              and  if  its  value is zero, the then list is executed.  If each
112              elif list returns nonzero, the else list is executed.
113
114       for name ... [ in word ... ] term do list done
115              where term is at least one newline or ;.   Expand  the  list  of
116              words,  and set the parameter name to each of them in turn, exe‐
117              cuting list each time.  If the in word is omitted, use the posi‐
118              tional parameters instead of the words.
119
120              More  than  one  parameter  name  can  appear before the list of
121              words.  If N names are given, then on each execution of the loop
122              the  next  N words are assigned to the corresponding parameters.
123              If there are more names  than  remaining  words,  the  remaining
124              parameters  are  each set to the empty string.  Execution of the
125              loop ends when there is no remaining word to assign to the first
126              name.  It is only possible for in to appear as the first name in
127              the list, else it will be treated as  marking  the  end  of  the
128              list.
129
130       for (( [expr1] ; [expr2] ; [expr3] )) do list done
131              The arithmetic expression expr1 is evaluated first (see the sec‐
132              tion `Arithmetic Evaluation').  The arithmetic expression  expr2
133              is  repeatedly  evaluated  until  it  evaluates to zero and when
134              non-zero, list is executed and the arithmetic  expression  expr3
135              evaluated.   If any expression is omitted, then it behaves as if
136              it evaluated to 1.
137
138       while list do list done
139              Execute the do list as long as the while  list  returns  a  zero
140              exit status.
141
142       until list do list done
143              Execute the do list as long as until list returns a nonzero exit
144              status.
145
146       repeat word do list done
147              word is expanded and treated as an arithmetic expression,  which
148              must evaluate to a number n.  list is then executed n times.
149
150       case word in [ [(] pattern [ | pattern ] ... ) list (;;|;&) ] ... esac
151              Execute  the list associated with the first pattern that matches
152              word, if any.  The form of the patterns is the same as that used
153              for filename generation.  See the section `Filename Generation'.
154              If the list that is executed is terminated with ;&  rather  than
155              ;;,  the  following list is also executed.  This continues until
156              either a list is terminated with ;; or the esac is reached.
157
158       select name [ in word ... term ] do list done
159              where term is one or more newline or ; to terminate  the  words.
160              Print  the  set  of words, each preceded by a number.  If the in
161              word is omitted, use the  positional  parameters.   The  PROMPT3
162              prompt is printed and a line is read from the line editor if the
163              shell is interactive and that is active, or else standard input.
164              If  this line consists of the number of one of the listed words,
165              then the parameter name is set to the word corresponding to this
166              number.   If  this  line is empty, the selection list is printed
167              again.  Otherwise, the value of the parameter  name  is  set  to
168              null.   The  contents  of  the  line read from standard input is
169              saved in the parameter REPLY.  list is executed for each  selec‐
170              tion until a break or end-of-file is encountered.
171
172       ( list )
173              Execute  list  in a subshell.  Traps set by the trap builtin are
174              reset to their default values while executing list.
175
176       { list }
177              Execute list.
178
179       { try-list } always { always-list }
180              First execute try-list.  Regardless of errors,  or  break,  con‐
181              tinue,  or  return commands encountered within try-list, execute
182              always-list.  Execution then continues from the  result  of  the
183              execution of try-list; in other words, any error, or break, con‐
184              tinue, or return command is treated in the  normal  way,  as  if
185              always-list  were  not  present.   The  two  chunks  of code are
186              referred to as the `try block' and the `always block'.
187
188              Optional newlines or semicolons may  appear  after  the  always;
189              note,  however,  that they may not appear between the preceeding
190              closing brace and the always.
191
192              An `error' in this context is a condition such as a syntax error
193              which  causes  the shell to abort execution of the current func‐
194              tion, script, or list.   Syntax  errors  encountered  while  the
195              shell  is  parsing  the  code do not cause the always-list to be
196              executed.  For example, an erroneously constructed if  block  in
197              try-list  would cause the shell to abort during parsing, so that
198              always-list would not be executed, while an erroneous  substitu‐
199              tion  such as ${*foo*} would cause a run-time error, after which
200              always-list would be executed.
201
202              An error condition can be tested  and  reset  with  the  special
203              integer  variable  TRY_BLOCK_ERROR.   Outside an always-list the
204              value is irrelevant,  but  it  is  initialised  to  -1.   Inside
205              always-list,  the  value  is  1  if  an  error  occurred  in the
206              try-list, else 0.  If TRY_BLOCK_ERROR is set  to  0  during  the
207              always-list,  the  error  condition  caused  by  the try-list is
208              reset, and shell execution continues normally after the  end  of
209              always-list.  Altering the value during the try-list is not use‐
210              ful (unless this forms part of an enclosing always block).
211
212              Regardless of TRY_BLOCK_ERROR, after the end of always-list  the
213              normal  shell  status $? is the value returned from always-list.
214              This  will  be  non-zero  if  there  was  an  error,   even   if
215              TRY_BLOCK_ERROR was set to zero.
216
217              The  following  executes  the given code, ignoring any errors it
218              causes.  This is an alternative to the usual convention of  pro‐
219              tecting code by executing it in a subshell.
220
221                     {
222                         # code which may cause an error
223                       } always {
224                         # This code is executed regardless of the error.
225                         (( TRY_BLOCK_ERROR = 0 ))
226                     }
227                     # The error condition has been reset.
228
229              An  exit command encountered in try-list does not cause the exe‐
230              cution of always-list.  Instead,  the  shell  exits  immediately
231              after any EXIT trap has been executed.
232
233       function word ... [ () ] [ term ] { list }
234       word ... () [ term ] { list }
235       word ... () [ term ] command
236              where term is one or more newline or ;.  Define a function which
237              is referenced by any one of word.  Normally, only  one  word  is
238              provided;  multiple  words  are  usually only useful for setting
239              traps.  The body of the function is the list between the  {  and
240              }.  See the section `Functions'.
241
242              If  the  option  SH_GLOB  is  set  for  compatibility with other
243              shells, then whitespace may appear between between the left  and
244              right  parentheses  when there is a single word;  otherwise, the
245              parentheses will be treated as forming  a  globbing  pattern  in
246              that case.
247
248       time [ pipeline ]
249              The  pipeline is executed, and timing statistics are reported on
250              the standard error in the form specified by the TIMEFMT  parame‐
251              ter.   If  pipeline is omitted, print statistics about the shell
252              process and its children.
253
254       [[ exp ]]
255              Evaluates the conditional expression exp and return a zero  exit
256              status if it is true.  See the section `Conditional Expressions'
257              for a description of exp.
258

ALTERNATE FORMS FOR COMPLEX COMMANDS

260       Many of zsh's complex commands have alternate forms.  These  particular
261       versions of complex commands should be considered deprecated and may be
262       removed in the future.  The versions in the previous section should  be
263       preferred instead.
264
265       The short versions below only work if sublist is of the form `{ list }'
266       or if the SHORT_LOOPS option is set.  For the if, while and until  com‐
267       mands, in both these cases the test part of the loop must also be suit‐
268       ably delimited, such as by `[[ ... ]]' or `(( ... ))', else the end  of
269       the  test will not be recognized.  For the for, repeat, case and select
270       commands no such special form for the arguments is necessary,  but  the
271       other  condition (the special form of sublist or use of the SHORT_LOOPS
272       option) still applies.
273
274       if list { list } [ elif list { list } ] ... [ else { list } ]
275              An alternate form of if.  The rules mean that
276
277                     if [[ -o ignorebraces ]] {
278                       print yes
279                     }
280
281              works, but
282
283                     if true {  # Does not work!
284                       print yes
285                     }
286
287              does not, since the test is not suitably delimited.
288
289       if list sublist
290              A short form of the alternate `if'.  The same limitations on the
291              form of list apply as for the previous form.
292
293       for name ... ( word ... ) sublist
294              A short form of for.
295
296       for name ... [ in word ... ] term sublist
297              where  term is at least one newline or ;.  Another short form of
298              for.
299
300       for (( [expr1] ; [expr2] ; [expr3] )) sublist
301              A short form of the arithmetic for command.
302
303       foreach name ... ( word ... ) list end
304              Another form of for.
305
306       while list { list }
307              An alternative form of while.  Note the limitations on the  form
308              of list mentioned above.
309
310       until list { list }
311              An  alternative form of until.  Note the limitations on the form
312              of list mentioned above.
313
314       repeat word sublist
315              This is a short form of repeat.
316
317       case word { [ [(] pattern [ | pattern ] ... ) list (;;|;&) ] ... }
318              An alternative form of case.
319
320       select name [ in word term ] sublist
321              where term is at least one  newline  or  ;.   A  short  form  of
322              select.
323

RESERVED WORDS

325       The  following  words are recognized as reserved words when used as the
326       first word of a command unless quoted or disabled using disable -r:
327
328       do done esac then elif else fi for case if while function  repeat  time
329       until select coproc nocorrect foreach end ! [[ { }
330
331       Additionally,  `}'  is  recognized in any position if the IGNORE_BRACES
332       option is not set.
333

COMMENTS

335       In noninteractive shells, or in interactive shells  with  the  INTERAC‐
336       TIVE_COMMENTS  option set, a word beginning with the third character of
337       the histchars parameter (`#' by default) causes that word and  all  the
338       following characters up to a newline to be ignored.
339

ALIASING

341       Every  token  in the shell input is checked to see if there is an alias
342       defined for it.  If so, it is replaced by the text of the alias  if  it
343       is  in command position (if it could be the first word of a simple com‐
344       mand), or if the alias is global.  If the text ends with a  space,  the
345       next  word  in  the shell input is treated as though it were in command
346       position for purposes of alias expansion.  An alias  is  defined  using
347       the alias builtin; global aliases may be defined using the -g option to
348       that builtin.
349
350       Alias expansion is done on the shell input before any  other  expansion
351       except  history  expansion.   Therefore, if an alias is defined for the
352       word foo, alias expansion may be avoided by quoting part of  the  word,
353       e.g.  \foo.  But there is nothing to prevent an alias being defined for
354       \foo as well.
355

QUOTING

357       A character may be quoted (that is, made to stand for itself)  by  pre‐
358       ceding it with a `\'.  `\' followed by a newline is ignored.
359
360       A string enclosed between `$'' and `'' is processed the same way as the
361       string arguments of the print builtin, and the resulting string is con‐
362       sidered to be entirely quoted.  A literal `'' character can be included
363       in the string by using the `\'' escape.
364
365       All characters enclosed between a pair of single quotes  ('')  that  is
366       not  preceded by a `$' are quoted.  A single quote cannot appear within
367       single quotes unless the option RC_QUOTES is set, in which case a  pair
368       of single quotes are turned into a single quote.  For example,
369
370              print ''''
371
372       outputs  nothing  apart from a newline if RC_QUOTES is not set, but one
373       single quote if it is set.
374
375       Inside double quotes (""), parameter and  command  substitution  occur,
376       and `\' quotes the characters `\', ``', `"', and `$'.
377

REDIRECTION

379       If  a  command is followed by & and job control is not active, then the
380       default standard input for the command is  the  empty  file  /dev/null.
381       Otherwise,  the environment for the execution of a command contains the
382       file descriptors of the invoking  shell  as  modified  by  input/output
383       specifications.
384
385       The following may appear anywhere in a simple command or may precede or
386       follow a complex command.  Expansion occurs before  word  or  digit  is
387       used except as noted below.  If the result of substitution on word pro‐
388       duces more than one filename,  redirection  occurs  for  each  separate
389       filename in turn.
390
391       < word Open file word for reading as standard input.
392
393       <> word
394              Open  file  word  for reading and writing as standard input.  If
395              the file does not exist then it is created.
396
397       > word Open file word for writing as standard output.  If the file does
398              not exist then it is created.  If the file exists, and the CLOB‐
399              BER option is unset, this causes  an  error;  otherwise,  it  is
400              truncated to zero length.
401
402       >| word
403       >! word
404              Same  as  >, except that the file is truncated to zero length if
405              it exists, even if CLOBBER is unset.
406
407       >> word
408              Open file word for writing in append mode  as  standard  output.
409              If  the  file  does  not exist, and the CLOBBER option is unset,
410              this causes an error; otherwise, the file is created.
411
412       >>| word
413       >>! word
414              Same as >>, except that the file  is  created  if  it  does  not
415              exist, even if CLOBBER is unset.
416
417       <<[-] word
418              The  shell  input is read up to a line that is the same as word,
419              or to an end-of-file.  No parameter expansion, command substitu‐
420              tion or filename generation is performed on word.  The resulting
421              document, called a here-document, becomes the standard input.
422
423              If any character of word is quoted with single or double  quotes
424              or a `\', no interpretation is placed upon the characters of the
425              document.  Otherwise, parameter and command substitution occurs,
426              `\'  followed  by  a newline is removed, and `\' must be used to
427              quote the characters `\', `$', ``' and the  first  character  of
428              word.
429
430              Note  that  word itself does not undergo shell expansion.  Back‐
431              quotes in word do not have  their  usual  effect;  instead  they
432              behave  similarly  to  double quotes, except that the backquotes
433              themselves are passed through unchanged.  (This  information  is
434              given for completeness and it is not recommended that backquotes
435              be used.)  Quotes in the form $'...' have their standard  effect
436              of expanding backslashed references to special characters.
437
438              If <<- is used, then all leading tabs are stripped from word and
439              from the document.
440
441       <<< word
442              Perform shell expansion on word and pass the result to  standard
443              input.  This is known as a here-string.  Compare the use of word
444              in here-documents above,  where  word  does  not  undergo  shell
445              expansion.
446
447       <& number
448       >& number
449              The  standard  input/output  is  duplicated from file descriptor
450              number (see dup2(2)).
451
452       <& -
453       >& -   Close the standard input/output.
454
455       <& p
456       >& p   The input/output from/to the coprocess is moved to the  standard
457              input/output.
458
459       >& word
460       &> word
461              (Except  where `>& word' matches one of the above syntaxes; `&>'
462              can always be used to avoid  this  ambiguity.)   Redirects  both
463              standard  output  and  standard error (file descriptor 2) in the
464              manner of `> word'.  Note that  this  does  not  have  the  same
465              effect as `> word 2>&1' in the presence of multios (see the sec‐
466              tion below).
467
468       >&| word
469       >&! word
470       &>| word
471       &>! word
472              Redirects both standard output and standard error (file descrip‐
473              tor 2) in the manner of `>| word'.
474
475       >>& word
476       &>> word
477              Redirects both standard output and standard error (file descrip‐
478              tor 2) in the manner of `>> word'.
479
480       >>&| word
481       >>&! word
482       &>>| word
483       &>>! word
484              Redirects both standard output and standard error (file descrip‐
485              tor 2) in the manner of `>>| word'.
486
487       If  one  of  the above is preceded by a digit, then the file descriptor
488       referred to is that specified by the digit instead of the default 0  or
489       1.   The order in which redirections are specified is significant.  The
490       shell evaluates each redirection in  terms  of  the  (file  descriptor,
491       file) association at the time of evaluation.  For example:
492
493              ... 1>fname 2>&1
494
495       first associates file descriptor 1 with file fname.  It then associates
496       file descriptor 2 with the file associated with file descriptor 1 (that
497       is,  fname).  If the order of redirections were reversed, file descrip‐
498       tor 2 would be associated with the terminal (assuming file descriptor 1
499       had  been)  and  then  file  descriptor 1 would be associated with file
500       fname.
501
502       The `|&' command separator described in Simple Commands & Pipelines  in
503       zshmisc(1) is a shorthand for `2>&1 |'.
504
505       For output redirections only, if word is of the form `>(list)' then the
506       output is piped to the command represented by list.  See  Process  Sub‐
507       stitution in zshexpn(1).
508

MULTIOS

510       If the user tries to open a file descriptor for writing more than once,
511       the shell opens the file descriptor as a pipe to a process that  copies
512       its  input  to  all the specified outputs, similar to tee, provided the
513       MULTIOS option is set, as it is by default.  Thus:
514
515              date >foo >bar
516
517       writes the date to two files, named `foo' and `bar'.  Note that a  pipe
518       is an implicit redirection; thus
519
520              date >foo | cat
521
522       writes the date to the file `foo', and also pipes it to cat.
523
524       If  the MULTIOS option is set, the word after a redirection operator is
525       also subjected to filename generation (globbing).  Thus
526
527              : > *
528
529       will truncate all files in the current directory, assuming  there's  at
530       least  one.  (Without the MULTIOS option, it would create an empty file
531       called `*'.)  Similarly, you can do
532
533              echo exit 0 >> *.sh
534
535       If the user tries to open a file descriptor for reading more than once,
536       the  shell opens the file descriptor as a pipe to a process that copies
537       all the specified inputs to its output in the order specified,  similar
538       to cat, provided the MULTIOS option is set.  Thus
539
540              sort <foo <fubar
541
542       or even
543
544              sort <f{oo,ubar}
545
546       is equivalent to `cat foo fubar | sort'.
547
548       Note that a pipe is an implicit redirection; thus
549
550              cat bar | sort <foo
551
552       is equivalent to `cat bar foo | sort' (note the order of the inputs).
553
554       If  the MULTIOS option is unset, each redirection replaces the previous
555       redirection for that file descriptor.  However, all files redirected to
556       are actually opened, so
557
558              echo foo > bar > baz
559
560       when MULTIOS is unset will truncate bar, and write `foo' into baz.
561
562       There  is  a  problem  when an output multio is attached to an external
563       program.  A simple example shows this:
564
565              cat file >file1 >file2
566              cat file1 file2
567
568       Here, it is possible that the second `cat' will not  display  the  full
569       contents  of  file1  and  file2  (i.e.  the  original  contents of file
570       repeated twice).
571
572       The reason for this is that the  multios  are  spawned  after  the  cat
573       process  is  forked from the parent shell, so the parent shell does not
574       wait for the multios to finish writing data.  This means the command as
575       shown  can  exit  before  file1 and file2 are completely written.  As a
576       workaround, it is possible to run the cat process as part of a  job  in
577       the current shell:
578
579              { cat file } >file >file2
580
581       Here, the {...} job will pause to wait for both files to be written.
582

REDIRECTIONS WITH NO COMMAND

584       When a simple command consists of one or more redirection operators and
585       zero or more parameter assignments, but no command name, zsh can behave
586       in several ways.
587
588       If  the  parameter NULLCMD is not set or the option CSH_NULLCMD is set,
589       an error is caused.  This is the csh behavior and CSH_NULLCMD is set by
590       default when emulating csh.
591
592       If  the option SH_NULLCMD is set, the builtin `:' is inserted as a com‐
593       mand with the given redirections.  This is the default  when  emulating
594       sh or ksh.
595
596       Otherwise, if the parameter NULLCMD is set, its value will be used as a
597       command with the given redirections.  If both NULLCMD  and  READNULLCMD
598       are  set,  then the value of the latter will be used instead of that of
599       the former when the redirection is an input.  The default  for  NULLCMD
600       is `cat' and for READNULLCMD is `more'. Thus
601
602              < file
603
604       shows the contents of file on standard output, with paging if that is a
605       terminal.  NULLCMD and READNULLCMD may refer to shell functions.
606

COMMAND EXECUTION

608       If a command name contains no slashes, the shell attempts to locate it.
609       If  there exists a shell function by that name, the function is invoked
610       as described in the section  `Functions'.   If  there  exists  a  shell
611       builtin by that name, the builtin is invoked.
612
613       Otherwise,  the  shell  searches  each element of $path for a directory
614       containing an executable file by that name.  If the  search  is  unsuc‐
615       cessful,  the  shell prints an error message and returns a nonzero exit
616       status.
617
618       If execution fails because the file is not in  executable  format,  and
619       the  file  is  not  a  directory,  it  is assumed to be a shell script.
620       /bin/sh is spawned to execute it.  If the program is a  file  beginning
621       with `#!', the remainder of the first line specifies an interpreter for
622       the program.  The shell will execute the specified interpreter on oper‐
623       ating systems that do not handle this executable format in the kernel.
624

FUNCTIONS

626       Shell functions are defined with the function reserved word or the spe‐
627       cial syntax `funcname ()'.  Shell functions  are  read  in  and  stored
628       internally.  Alias names are resolved when the function is read.  Func‐
629       tions are executed like commands with the  arguments  passed  as  posi‐
630       tional parameters.  (See the section `Command Execution'.)
631
632       Functions execute in the same process as the caller and share all files
633       and present working directory with the caller.   A  trap  on  EXIT  set
634       inside a function is executed after the function completes in the envi‐
635       ronment of the caller.
636
637       The return builtin is used to return from function calls.
638
639       Function identifiers can be listed with the functions  builtin.   Func‐
640       tions can be undefined with the unfunction builtin.
641

AUTOLOADING FUNCTIONS

643       A  function  can  be marked as undefined using the autoload builtin (or
644       `functions -u' or `typeset -fu').  Such a function has no  body.   When
645       the  function  is first executed, the shell searches for its definition
646       using the elements of the fpath variable.  Thus to define functions for
647       autoloading, a typical sequence is:
648
649              fpath=(~/myfuncs $fpath)
650              autoload myfunc1 myfunc2 ...
651
652       The  usual  alias  expansion  during  reading will be suppressed if the
653       autoload builtin or its equivalent is given the option -U. This is rec‐
654       ommended  for  the use of functions supplied with the zsh distribution.
655       Note that for functions precompiled with the zcompile  builtin  command
656       the flag -U must be provided when the .zwc file is created, as the cor‐
657       responding information is compiled into the latter.
658
659       For each element in fpath, the shell looks for  three  possible  files,
660       the newest of which is used to load the definition for the function:
661
662       element.zwc
663              A  file  created  with  the  zcompile  builtin command, which is
664              expected to contain the definitions for  all  functions  in  the
665              directory named element.  The file is treated in the same manner
666              as a directory containing files for functions  and  is  searched
667              for  the  definition of the function.   If the definition is not
668              found, the search for a definition proceeds with the  other  two
669              possibilities described below.
670
671              If element already includes a .zwc extension (i.e. the extension
672              was explicitly given by the user), element is searched  for  the
673              definition  of the function without comparing its age to that of
674              other files; in fact, there does not need to  be  any  directory
675              named  element  without  the  suffix.  Thus including an element
676              such as `/usr/local/funcs.zwc' in fpath will speed up the search
677              for  functions,  with  the  disadvantage that functions included
678              must be explicitly recompiled by hand before the  shell  notices
679              any changes.
680
681       element/function.zwc
682              A  file  created with zcompile, which is expected to contain the
683              definition for function.  It may include other function  defini‐
684              tions as well, but those are neither loaded nor executed; a file
685              found in this way is searched only for the definition  of  func‐
686              tion.
687
688       element/function
689              A file of zsh command text, taken to be the definition for func‐
690              tion.
691
692       In summary, the order of searching is, first, in the parents of  direc‐
693       tories  in  fpath  for  the  newer  of either a compiled directory or a
694       directory in fpath; second, if more than one of these contains a  defi‐
695       nition  for  the  function that is sought, the leftmost in the fpath is
696       chosen; and third, within a directory, the newer of either  a  compiled
697       function or an ordinary function definition is used.
698
699       If  the  KSH_AUTOLOAD option is set, or the file contains only a simple
700       definition of the function, the file's contents will be executed.  This
701       will  normally  define  the  function in question, but may also perform
702       initialization, which is executed in the context of the function execu‐
703       tion, and may therefore define local parameters.  It is an error if the
704       function is not defined by loading the file.
705
706       Otherwise, the function body (with no surrounding  `funcname()  {...}')
707       is taken to be the complete contents of the file.  This form allows the
708       file to be used directly as an executable shell script.  If  processing
709       of  the  file  results  in  the function being re-defined, the function
710       itself is not re-executed.  To force the shell to  perform  initializa‐
711       tion  and  then call the function defined, the file should contain ini‐
712       tialization code (which will be executed then discarded) in addition to
713       a  complete  function definition (which will be retained for subsequent
714       calls to the function), and a call to the shell function, including any
715       arguments, at the end.
716
717       For example, suppose the autoload file func contains
718
719              func() { print This is func; }
720              print func is initialized
721
722       then  `func;  func' with KSH_AUTOLOAD set will produce both messages on
723       the first call, but only the message `This is func' on the  second  and
724       subsequent  calls.   Without KSH_AUTOLOAD set, it will produce the ini‐
725       tialization message on the first call, and the  other  message  on  the
726       second and subsequent calls.
727
728       It  is  also  possible  to  create  a  function  that  is not marked as
729       autoloaded, but which loads its own definition by searching  fpath,  by
730       using  `autoload -X' within a shell function.  For example, the follow‐
731       ing are equivalent:
732
733              myfunc() {
734                autoload -X
735              }
736              myfunc args...
737
738       and
739
740              unfunction myfunc   # if myfunc was defined
741              autoload myfunc
742              myfunc args...
743
744       In fact, the functions command outputs `builtin  autoload  -X'  as  the
745       body of an autoloaded function.  This is done so that
746
747              eval "$(functions)"
748
749       produces  a reasonable result.  A true autoloaded function can be iden‐
750       tified by the presence of  the  comment  `#  undefined'  in  the  body,
751       because all comments are discarded from defined functions.
752
753       To load the definition of an autoloaded function myfunc without execut‐
754       ing myfunc, use:
755
756              autoload +X myfunc
757

SPECIAL FUNCTIONS

759       The following functions, if defined, have special meaning to the shell:
760
761       chpwd  Executed whenever the current working directory is changed.
762
763       periodic
764              If the parameter PERIOD is set, this function is executed  every
765              $PERIOD seconds, just before a prompt.
766
767       precmd Executed before each prompt.
768
769       preexec
770              Executed  just  after a command has been read and is about to be
771              executed.  If the history mechanism is active (and the line  was
772              not discarded from the history buffer), the string that the user
773              typed is passed as the first argument, otherwise it is an  empty
774              string.   The  actual  command  that will be executed (including
775              expanded aliases) is passed in two different forms:  the  second
776              argument  is  a single-line, size-limited version of the command
777              (with things like function bodies elided);  the  third  argument
778              contains the full text that is being executed.
779
780       TRAPNAL
781              If defined and non-null, this function will be executed whenever
782              the shell catches a signal SIGNAL, where NAL is a signal name as
783              specified  for  the  kill  builtin.   The  signal number will be
784              passed as the first parameter to the function.
785
786              If a function of this form is defined and null,  the  shell  and
787              processes spawned by it will ignore SIGNAL.
788
789              The  return value from the function is handled specially.  If it
790              is zero, the signal is assumed to have been handled, and  execu‐
791              tion  continues  normally.   Otherwise, the normal effect of the
792              signal is produced; if this causes execution to  terminate,  the
793              status  returned  to  the  shell is the status returned from the
794              function.
795
796              Programs terminated by uncaught  signals  typically  return  the
797              status  128  plus the signal number.  Hence the following causes
798              the handler for SIGINT to print a message, then mimic the  usual
799              effect of the signal.
800
801                     TRAPINT() {
802                       print "Caught SIGINT, aborting."
803                       return $(( 128 + $1 ))
804                     }
805
806              The  functions  TRAPZERR,  TRAPDEBUG and TRAPEXIT are never exe‐
807              cuted inside other traps.
808
809       TRAPDEBUG
810              Executed after each command.
811
812       TRAPEXIT
813              Executed when the shell exits,  or  when  the  current  function
814              exits if defined inside a function.
815
816       TRAPZERR
817              Executed  whenever  a  command has a non-zero exit status.  How‐
818              ever, the function is not executed if the command occurred in  a
819              sublist  followed  by  `&&' or `||'; only the final command in a
820              sublist of this type causes the trap to be executed.
821
822       The functions beginning `TRAP' may alternatively be  defined  with  the
823       trap  builtin:   this may be preferable for some uses, as they are then
824       run in the environment of the calling process, rather than in their own
825       function  environment.   Apart from the difference in calling procedure
826       and the fact that the function form appears in lists of functions,  the
827       forms
828
829              TRAPNAL() {
830               # code
831              }
832
833       and
834
835              trap '
836               # code
837
838       are equivalent.
839

JOBS

841       If  the  MONITOR  option  is set, an interactive shell associates a job
842       with each pipeline.  It keeps a table of current jobs, printed  by  the
843       jobs  command,  and  assigns them small integer numbers.  When a job is
844       started asynchronously with `&', the shell prints a  line  to  standard
845       error which looks like:
846
847              [1] 1234
848
849       indicating that the job which was started asynchronously was job number
850       1 and had one (top-level) process, whose process ID was 1234.
851
852       If a job is started with `&|' or `&!', then  that  job  is  immediately
853       disowned.   After  startup,  it does not have a place in the job table,
854       and is not subject to the job control features described here.
855
856       If you are running a job and wish to do something else you may hit  the
857       key  ^Z (control-Z) which sends a TSTP signal to the current job:  this
858       key may be redefined by the susp option of the external  stty  command.
859       The  shell  will  then  normally  indicate  that the job has been `sus‐
860       pended', and print another prompt.  You can then manipulate  the  state
861       of  this  job, putting it in the background with the bg command, or run
862       some other commands and then eventually bring the  job  back  into  the
863       foreground  with  the foreground command fg.  A ^Z takes effect immedi‐
864       ately and is like an interrupt in that pending output and unread  input
865       are discarded when it is typed.
866
867       A job being run in the background will suspend if it tries to read from
868       the terminal.  Background jobs are normally allowed to produce  output,
869       but  this  can be disabled by giving the command `stty tostop'.  If you
870       set this tty option, then background jobs will suspend when they try to
871       produce output like they do when they try to read input.
872
873       When  a  command  is  suspended and continued later with the fg or wait
874       builtins, zsh restores tty modes that were in effect when it  was  sus‐
875       pended.   This (intentionally) does not apply if the command is contin‐
876       ued via `kill -CONT', nor when it is continued with bg.
877
878       There are several ways to refer to jobs in the shell.   A  job  can  be
879       referred  to  by  the process ID of any process of the job or by one of
880       the following:
881
882       %number
883              The job with the given number.
884       %string
885              Any job whose command line begins with string.
886       %?string
887              Any job whose command line contains string.
888       %%     Current job.
889       %+     Equivalent to `%%'.
890       %-     Previous job.
891
892       The shell learns immediately whenever a process changes state.  It nor‐
893       mally  informs  you  whenever  a job becomes blocked so that no further
894       progress is possible.  If the NOTIFY option is not set, it waits  until
895       just before it prints a prompt before it informs you.  All such notifi‐
896       cations are sent directly to the terminal, not to the  standard  output
897       or standard error.
898
899       When  the  monitor mode is on, each background job that completes trig‐
900       gers any trap set for CHLD.
901
902       When you try to leave the shell while jobs are  running  or  suspended,
903       you  will  be warned that `You have suspended (running) jobs'.  You may
904       use the jobs command to see what they are.  If you do this  or  immedi‐
905       ately try to exit again, the shell will not warn you a second time; the
906       suspended jobs will be terminated, and the running jobs will be sent  a
907       SIGHUP signal, if the HUP option is set.
908
909       To  avoid  having  the shell terminate the running jobs, either use the
910       nohup command (see nohup(1)) or the disown builtin.
911

SIGNALS

913       The INT and QUIT signals for an invoked command are ignored if the com‐
914       mand  is  followed by `&' and the MONITOR option is not active.  Other‐
915       wise, signals have the values inherited by the shell  from  its  parent
916       (but see the TRAPNAL special functions in the section `Functions').
917

ARITHMETIC EVALUATION

919       The  shell  can  perform  integer and floating point arithmetic, either
920       using the builtin let, or via a substitution of the form $((...)).  For
921       integers,  the  shell is usually compiled to use 8-byte precision where
922       this is available, otherwise precision is 4 bytes.  This can be tested,
923       for example, by giving the command `print - $(( 12345678901 ))'; if the
924       number appears unchanged, the precision is at least 8 bytes.   Floating
925       point arithmetic is always double precision.
926
927       The let builtin command takes arithmetic expressions as arguments; each
928       is evaluated separately.  Since many of the  arithmetic  operators,  as
929       well  as  spaces, require quoting, an alternative form is provided: for
930       any command which begins with a `((', all the characters until a match‐
931       ing  `))'  are  treated as a quoted expression and arithmetic expansion
932       performed as for an argument of  let.   More  precisely,  `((...))'  is
933       equivalent to `let "..."'.  For example, the following statement
934
935              (( val = 2 + 1 ))
936
937       is equivalent to
938
939              let "val = 2 + 1"
940
941       both  assigning  the  value 3 to the shell variable val and returning a
942       zero status.
943
944       Integers can be in bases other than 10.  A leading `0x' or `0X' denotes
945       hexadecimal.   Integers may also be of the form `base#n', where base is
946       a decimal number between two and thirty-six representing the arithmetic
947       base  and  n  is  a number in that base (for example, `16#ff' is 255 in
948       hexadecimal).  The base# may also be omitted, in which case base 10  is
949       used.  For backwards compatibility the form `[base]n' is also accepted.
950
951       It is also possible to specify a base to be used for output in the form
952       `[#base]', for example `[#16]'.  This is used  when  outputting  arith‐
953       metical  substitutions  or  when assigning to scalar parameters, but an
954       explicitly defined integer or floating  point  parameter  will  not  be
955       affected.   If  an  integer variable is implicitly defined by an arith‐
956       metic expression, any base specified in this way will  be  set  as  the
957       variable's  output  arithmetic  base  as if the option `-i base' to the
958       typeset builtin had been used.  The expression has no precedence and if
959       it occurs more than once in a mathematical expression, the last encoun‐
960       tered is used.  For clarity it is recommended that  it  appear  at  the
961       beginning of an expression.  As an example:
962
963              typeset -i 16 y
964              print $(( [#8] x = 32, y = 32 ))
965              print $x $y
966
967       outputs first `8#40', the rightmost value in the given output base, and
968       then `8#40 16#20', because y has been explicitly declared to have  out‐
969       put base 16, while x (assuming it does not already exist) is implicitly
970       typed by the arithmetic evaluation, where it acquires the  output  base
971       8.
972
973       If  the  C_BASES  option  is set, hexadecimal numbers in the standard C
974       format, for example 0xFF instead of the usual `16#FF'.  If  the  option
975       OCTAL_ZEROES  is also set (it is not by default), octal numbers will be
976       treated similarly and hence appear as `077' instead  of  `8#77'.   This
977       option  has no effect on the output of bases other than hexadecimal and
978       octal, and these formats are always understood on input.
979
980       When an output base is specified using the `[#base]' syntax, an  appro‐
981       priate  base prefix will be output if necessary, so that the value out‐
982       put is valid syntax for input.   If  the  #  is  doubled,  for  example
983       `[##16]', then no base prefix is output.
984
985       Floating  point  constants  are recognized by the presence of a decimal
986       point or an exponent.  The decimal point may be the first character  of
987       the  constant, but the exponent character e or E may not, as it will be
988       taken for a parameter name.
989
990       An arithmetic expression uses nearly the same syntax,  precedence,  and
991       associativity  of  expressions  in C.  The following operators are sup‐
992       ported (listed in decreasing order of precedence):
993
994       + - ! ~ ++ --
995              unary plus/minus, logical NOT, complement, {pre,post}{in,de}cre‐
996              ment
997       << >>  bitwise shift left, right
998       &      bitwise AND
999       ^      bitwise XOR
1000       |      bitwise OR
1001       **     exponentiation
1002       * / %  multiplication, division, modulus (remainder)
1003       + -    addition, subtraction
1004       < > <= >=
1005              comparison
1006       == !=  equality and inequality
1007       &&     logical AND
1008       || ^^  logical OR, XOR
1009       ? :    ternary operator
1010       = += -= *= /= %= &= ^= |= <<= >>= &&= ||= ^^= **=
1011              assignment
1012       ,      comma operator
1013
1014       The  operators  `&&',  `||', `&&=', and `||=' are short-circuiting, and
1015       only one of the latter two expressions in a ternary operator is  evalu‐
1016       ated.  Note the precedence of the bitwise AND, OR, and XOR operators.
1017
1018       Mathematical  functions  can  be  called  with the syntax `func(args)',
1019       where the function decides if the  args  is  used  as  a  string  or  a
1020       comma-separated  list  of  arithmetic  expressions. The shell currently
1021       defines no mathematical functions by default, but the module  zsh/math‐
1022       func may be loaded with the zmodload builtin to provide standard float‐
1023       ing point mathematical functions.
1024
1025       An expression of the form `##x' where x is any character sequence  such
1026       as  `a', `^A', or `\M-\C-x' gives the ASCII value of this character and
1027       an expression of the form `#foo' gives the ASCII  value  of  the  first
1028       character of the value of the parameter foo.  Note that this is differ‐
1029       ent from the expression  `$#foo',  a  standard  parameter  substitution
1030       which  gives the length of the parameter foo.  `#\' is accepted instead
1031       of `##', but its use is deprecated.
1032
1033       Named parameters and subscripted  arrays  can  be  referenced  by  name
1034       within  an  arithmetic expression without using the parameter expansion
1035       syntax.  For example,
1036
1037              ((val2 = val1 * 2))
1038
1039       assigns twice the value of $val1 to the parameter named val2.
1040
1041       An internal integer representation of a named parameter can  be  speci‐
1042       fied  with  the integer builtin.  Arithmetic evaluation is performed on
1043       the value of each assignment to a named parameter declared  integer  in
1044       this  manner.   Assigning a floating point number to an integer results
1045       in rounding down to the next integer.
1046
1047       Likewise, floating  point  numbers  can  be  declared  with  the  float
1048       builtin; there are two types, differing only in their output format, as
1049       described for the typeset builtin.  The output format can  be  bypassed
1050       by using arithmetic substitution instead of the parameter substitution,
1051       i.e. `${float}' uses  the  defined  format,  but  `$((float))'  uses  a
1052       generic floating point format.
1053
1054       Promotion of integer to floating point values is performed where neces‐
1055       sary.  In addition, if any operator which  requires  an  integer  (`~',
1056       `&',  `|',  `^', `%', `<<', `>>' and their equivalents with assignment)
1057       is given a floating point argument, it will be silently rounded down to
1058       the next integer.
1059
1060       Scalar variables can hold integer or floating point values at different
1061       times; there is no memory of the numeric type in this case.
1062
1063       If a variable is first assigned in a numeric context without previously
1064       being  declared,  it  will  be implicitly typed as integer or float and
1065       retain that type either until the type is explicitly changed  or  until
1066       the  end  of  the  scope.   This can have unforeseen consequences.  For
1067       example, in the loop
1068
1069              for (( f = 0; f < 1; f += 0.1 )); do
1070              # use $f
1071              done
1072
1073       if f has not already been declared, the first assignment will cause  it
1074       to  be created as an integer, and consequently the operation `f += 0.1'
1075       will always cause the result to be truncated to zero, so that the  loop
1076       will  fail.  A simple fix would be to turn the initialization into `f =
1077       0.0'.  It is therefore best to declare numeric variables with  explicit
1078       types.
1079

CONDITIONAL EXPRESSIONS

1081       A  conditional  expression is used with the [[ compound command to test
1082       attributes of files and to compare strings.   Each  expression  can  be
1083       constructed  from  one or more of the following unary or binary expres‐
1084       sions:
1085
1086       -a file
1087              true if file exists.
1088
1089       -b file
1090              true if file exists and is a block special file.
1091
1092       -c file
1093              true if file exists and is a character special file.
1094
1095       -d file
1096              true if file exists and is a directory.
1097
1098       -e file
1099              true if file exists.
1100
1101       -f file
1102              true if file exists and is a regular file.
1103
1104       -g file
1105              true if file exists and has its setgid bit set.
1106
1107       -h file
1108              true if file exists and is a symbolic link.
1109
1110       -k file
1111              true if file exists and has its sticky bit set.
1112
1113       -n string
1114              true if length of string is non-zero.
1115
1116       -o option
1117              true if option named option is on.  option may be a single char‐
1118              acter,  in  which  case it is a single letter option name.  (See
1119              the section `Specifying Options'.)
1120
1121       -p file
1122              true if file exists and is a FIFO special file (named pipe).
1123
1124       -r file
1125              true if file exists and is readable by current process.
1126
1127       -s file
1128              true if file exists and has size greater than zero.
1129
1130       -t fd  true if file descriptor number fd is open and associated with  a
1131              terminal device.  (note: fd is not optional)
1132
1133       -u file
1134              true if file exists and has its setuid bit set.
1135
1136       -w file
1137              true if file exists and is writable by current process.
1138
1139       -x file
1140              true  if  file  exists and is executable by current process.  If
1141              file exists and is a directory, then  the  current  process  has
1142              permission to search in the directory.
1143
1144       -z string
1145              true if length of string is zero.
1146
1147       -L file
1148              true if file exists and is a symbolic link.
1149
1150       -O file
1151              true  if  file  exists  and is owned by the effective user ID of
1152              this process.
1153
1154       -G file
1155              true if file exists and its group matches the effective group ID
1156              of this process.
1157
1158       -S file
1159              true if file exists and is a socket.
1160
1161       -N file
1162              true  if  file  exists and its access time is not newer than its
1163              modification time.
1164
1165       file1 -nt file2
1166              true if file1 exists and is newer than file2.
1167
1168       file1 -ot file2
1169              true if file1 exists and is older than file2.
1170
1171       file1 -ef file2
1172              true if file1 and file2 exist and refer to the same file.
1173
1174       string = pattern
1175       string == pattern
1176              true if string matches pattern.  The `==' form is the  preferred
1177              one.   The  `=' form is for backward compatibility and should be
1178              considered obsolete.
1179
1180       string != pattern
1181              true if string does not match pattern.
1182
1183       string1 < string2
1184              true if string1 comes before string2 based  on  ASCII  value  of
1185              their characters.
1186
1187       string1 > string2
1188              true  if  string1  comes  after  string2 based on ASCII value of
1189              their characters.
1190
1191       exp1 -eq exp2
1192              true if exp1 is numerically equal to exp2.
1193
1194       exp1 -ne exp2
1195              true if exp1 is numerically not equal to exp2.
1196
1197       exp1 -lt exp2
1198              true if exp1 is numerically less than exp2.
1199
1200       exp1 -gt exp2
1201              true if exp1 is numerically greater than exp2.
1202
1203       exp1 -le exp2
1204              true if exp1 is numerically less than or equal to exp2.
1205
1206       exp1 -ge exp2
1207              true if exp1 is numerically greater than or equal to exp2.
1208
1209       ( exp )
1210              true if exp is true.
1211
1212       ! exp  true if exp is false.
1213
1214       exp1 && exp2
1215              true if exp1 and exp2 are both true.
1216
1217       exp1 || exp2
1218              true if either exp1 or exp2 is true.
1219
1220       Normal shell expansion is performed on the  file,  string  and  pattern
1221       arguments, but the result of each expansion is constrained to be a sin‐
1222       gle word, similar to the effect of  double  quotes.   However,  pattern
1223       metacharacters  are  active for the pattern arguments; the patterns are
1224       the same as those used for filename  generation,  see  zshexpn(1),  but
1225       there  is  no  special  behaviour  of `/' nor initial dots, and no glob
1226       qualifiers are allowed.
1227
1228       In each of the above expressions, if file is of the  form  `/dev/fd/n',
1229       where  n  is  an  integer, then the test applied to the open file whose
1230       descriptor number is n, even if the underlying system does not  support
1231       the /dev/fd directory.
1232
1233       In  the  forms which do numeric comparison, the expressions exp undergo
1234       arithmetic expansion as if they were enclosed in $((...)).
1235
1236       For example, the following:
1237
1238              [[ ( -f foo || -f bar ) && $report = y* ]] && print File exists.
1239
1240       tests if either file foo or file bar exists, and if so, if the value of
1241       the  parameter  report  begins  with  `y'; if the complete condition is
1242       true, the message `File exists.' is printed.
1243

PROMPT EXPANSION

1245       Prompt sequences undergo a special form of  expansion.   This  type  of
1246       expansion is also available using the -P option to the print builtin.
1247
1248       If the PROMPT_SUBST option is set, the prompt string is first subjected
1249       to parameter expansion, command substitution and arithmetic  expansion.
1250       See zshexpn(1).
1251
1252       Certain escape sequences may be recognised in the prompt string.
1253
1254       If  the  PROMPT_BANG  option is set, a `!' in the prompt is replaced by
1255       the current history event number.  A literal `!'  may  then  be  repre‐
1256       sented as `!!'.
1257
1258       If  the  PROMPT_PERCENT  option  is  set, certain escape sequences that
1259       start with `%' are expanded.  Some escapes  take  an  optional  integer
1260       argument, which should appear between the `%' and the next character of
1261       the sequence.  The following escape sequences are recognized:
1262
1263   Special characters
1264       %%     A `%'.
1265
1266       %)     A `)'.
1267
1268   Login information
1269       %l     The line (tty) the user is logged in on, without `/dev/' prefix.
1270              If the name starts with `/dev/tty', that prefix is stripped.
1271
1272       %M     The full machine hostname.
1273
1274       %m     The hostname up to the first `.'.  An integer may follow the `%'
1275              to specify how many components  of  the  hostname  are  desired.
1276              With a negative integer, trailing components of the hostname are
1277              shown.
1278
1279       %n     $USERNAME.
1280
1281       %y     The line (tty) the user is logged in on, without `/dev/' prefix.
1282              This does not treat `/dev/tty' names specially.
1283
1284   Shell state
1285       %#     A  `#'  if  the  shell is running with privileges, a `%' if not.
1286              Equivalent to `%(!.#.%%)'.  The definition of `privileged',  for
1287              these  purposes,  is  that either the effective user ID is zero,
1288              or, if POSIX.1e capabilities are supported, that  at  least  one
1289              capability  is  raised  in  either  the Effective or Inheritable
1290              capability vectors.
1291
1292       %?     The return code of the last command  executed  just  before  the
1293              prompt.
1294
1295       %_     The  status  of the parser, i.e. the shell constructs (like `if'
1296              and `for') that have been started on the command line. If  given
1297              an  integer  number  that  many strings will be printed; zero or
1298              negative or no integer means print as many as there  are.   This
1299              is most useful in prompts PS2 for continuation lines and PS4 for
1300              debugging with the XTRACE option; in the  latter  case  it  will
1301              also work non-interactively.
1302
1303       %d
1304       %/     Present  working  directory  ($PWD).   If an integer follows the
1305              `%', it specifies a number of trailing  components  of  $PWD  to
1306              show;  zero  means the whole path.  A negative integer specifies
1307              leading components, i.e. %-1d specifies the first component.
1308
1309       %~     As %d and %/, but if $PWD has a named directory as  its  prefix,
1310              that  part  is  replaced  by  a  `~' followed by the name of the
1311              directory.  If it starts with $HOME, that part is replaced by  a
1312              `~'.
1313
1314       %h
1315       %!     Current history event number.
1316
1317       %i     The  line number currently being executed in the script, sourced
1318              file, or shell function given by %N.  This is  most  useful  for
1319              debugging as part of $PS4.
1320
1321       %j     The number of jobs.
1322
1323       %L     The current value of $SHLVL.
1324
1325       %N     The name of the script, sourced file, or shell function that zsh
1326              is currently executing, whichever was started most recently.  If
1327              there is none, this is equivalent to the parameter $0.  An inte‐
1328              ger may follow the `%' to specify a number of trailing path com‐
1329              ponents  to  show; zero means the full path.  A negative integer
1330              specifies leading components.
1331
1332       %c
1333       %.
1334       %C     Trailing component of $PWD.  An integer may follow  the  `%'  to
1335              get  more  than  one component.  Unless `%C' is used, tilde con‐
1336              traction is performed first.  These are deprecated as %c and  %C
1337              are equivalent to %1~ and %1/, respectively, while explicit pos‐
1338              itive integers have the  same  effect  as  for  the  latter  two
1339              sequences.
1340
1341   Date and time
1342       %D     The date in yy-mm-dd format.
1343
1344       %T     Current time of day, in 24-hour format.
1345
1346       %t
1347       %@     Current time of day, in 12-hour, am/pm format.
1348
1349       %*     Current time of day in 24-hour format, with seconds.
1350
1351       %w     The date in day-dd format.
1352
1353       %W     The date in mm/dd/yy format.
1354
1355       %D{string}
1356              string  is  formatted  using  the  strftime function.  See strf‐
1357              time(3) for more details.  Three additional codes are available:
1358              %f  prints the day of the month, like %e but without any preced‐
1359              ing space if the day is a single digit, and %K/%L correspond  to
1360              %k/%l  for  the  hour  of the day (24/12 hour clock) in the same
1361              way.
1362
1363   Visual effects
1364       %B (%b)
1365              Start (stop) boldface mode.
1366
1367       %E     Clear to end of line.
1368
1369       %U (%u)
1370              Start (stop) underline mode.
1371
1372       %S (%s)
1373              Start (stop) standout mode.
1374
1375       %{...%}
1376              Include a string as  a  literal  escape  sequence.   The  string
1377              within  the braces should not change the cursor position.  Brace
1378              pairs can nest.
1379
1380   Conditional substrings
1381       %v     The value of the first element of  the  psvar  array  parameter.
1382              Following  the  `%'  with  an  integer gives that element of the
1383              array.  Negative integers count from the end of the array.
1384
1385       %(x.true-text.false-text)
1386              Specifies a ternary expression.  The character following  the  x
1387              is  arbitrary;  the  same character is used to separate the text
1388              for the `true' result from that for the  `false'  result.   This
1389              separator  may  not appear in the true-text, except as part of a
1390              %-escape sequence.  A `)' may appear in the false-text as  `%)'.
1391              true-text  and  false-text  may  both contain arbitrarily-nested
1392              escape sequences, including further ternary expressions.
1393
1394              The left parenthesis may be preceded or followed by  a  positive
1395              integer  n,  which defaults to zero.  A negative integer will be
1396              multiplied by -1.  The test character x may be any of  the  fol‐
1397              lowing:
1398
1399              !      True if the shell is running with privileges.
1400              #      True if the effective uid of the current process is n.
1401              ?      True if the exit status of the last command was n.
1402              _      True if at least n shell constructs were started.
1403              C
1404              /      True if the current absolute path has at least n elements
1405                     relative to the root directory, hence / is counted  as  0
1406                     elements.
1407              c
1408              .
1409              ~      True if the current path, with prefix replacement, has at
1410                     least n elements relative to the root directory, hence  /
1411                     is counted as 0 elements.
1412              D      True if the month is equal to n (January = 0).
1413              d      True if the day of the month is equal to n.
1414              g      True if the effective gid of the current process is n.
1415              j      True if the number of jobs is at least n.
1416              L      True if the SHLVL parameter is at least n.
1417              l      True  if  at least n characters have already been printed
1418                     on the current line.
1419              S      True if the SECONDS parameter is at least n.
1420              T      True if the time in hours is equal to n.
1421              t      True if the time in minutes is equal to n.
1422              v      True if the array psvar has at least n elements.
1423              w      True if the day of the week is equal to n (Sunday = 0).
1424
1425       %<string<
1426       %>string>
1427       %[xstring]
1428              Specifies truncation behaviour for the remainder of  the  prompt
1429              string.    The   third,   deprecated,   form  is  equivalent  to
1430              `%xstringx', i.e. x may be `<' or `>'.   The  numeric  argument,
1431              which  in  the  third form may appear immediately after the `[',
1432              specifies the maximum permitted length of  the  various  strings
1433              that  can  be  displayed in the prompt.  The string will be dis‐
1434              played in place of the truncated portion  of  any  string;  note
1435              this does not undergo prompt expansion.
1436
1437              The  forms  with `<' truncate at the left of the string, and the
1438              forms with `>' truncate at the right of the string.   For  exam‐
1439              ple,  if  the  current  directory  is  `/home/pike',  the prompt
1440              `%8<..<%/' will expand to `..e/pike'.  In this string, the  ter‐
1441              minating  character (`<', `>' or `]'), or in fact any character,
1442              may be quoted by a preceding `\'; note when using print -P, how‐
1443              ever, that this must be doubled as the string is also subject to
1444              standard  print  processing,  in  addition  to  any  backslashes
1445              removed  by a double quoted string:  the worst case is therefore
1446              `print -P "%<\\\\<<..."'.
1447
1448              If the string is longer than the specified truncation length, it
1449              will appear in full, completely replacing the truncated string.
1450
1451              The part of the prompt string to be truncated runs to the end of
1452              the string, or to the end of the next  enclosing  group  of  the
1453              `%('  construct,  or  to  the next truncation encountered at the
1454              same grouping level (i.e. truncations inside a  `%('  are  sepa‐
1455              rate), which ever comes first.  In particular, a truncation with
1456              argument zero (e.g. `%<<') marks the end of  the  range  of  the
1457              string  to  be truncated while turning off truncation from there
1458              on. For example, the prompt  '%10<...<%~%<<%#  '  will  print  a
1459              truncated representation of the current directory, followed by a
1460              `%' or `#', followed by a space.  Without the `%<<',  those  two
1461              characters would be included in the string to be truncated.
1462
1463
1464
1465zsh 4.2.6                      November 28, 2005                    ZSHMISC(1)
Impressum