   This is a texinfo version of the man page for the Z Shell, by Paul
Falstad.  It was converted from the original `zsh.1' file distributed
with zsh v2.4.291.  The conversion was done by Jonathan Hardwick,
`jch@cs.cmu.edu', who would love to hear of any errors he introduced or
texinfo rules he broke.  The text remains the work of Paul Falstad.

 -- Indices --

Wrapping Up

Shell Grammar
*************

Simple Commands
===============

A "simple command" is a sequence of optional parameter assignments
followed by blank-separated words, with optional redirections
interspersed.  The first word is the command to be executed, and the
remaining words, if any, are arguments to the command.  If a command
name is given, the parameter assignments modify the environment of the
command when it is executed.  The value of a simple command is its exit
status, or 128 plus the signal number if terminated by a signal.

If a simple command is preceded by the word `exec', it is executed in
the parent shell without forking.  If preceded by `command', the
command word is taken to be the name of an external command, rather than
a shell function or builtin.  If preceded by `noglob', filename
generation is not performed on any of the words.  If preceded by a `-',
the command is executed with a `-' prepended to its `argv[0]' string.
If preceded by `nocorrect', spelling correction is not done on any of
the words.

A "pipeline" is a sequence of one or more commands separated by `|' or
`|&'.  `|&' is shorthand for `2>&1 |'.  The standard output of each
command is connected to the standard input of the next command in the
pipeline.

The value of a pipeline is the value of the last command.  If a pipeline
is preceded by a `!', the value of that pipeline is the logical NOT of
the value of the last command.

If a pipeline is preceded by `coproc', it is executed as a coprocess; a
two-way pipe is established between it and the parent shell.  The shell
can read from or write to the coprocess by means of the `>&p' and `<&p'
redirection operators.

A "sublist" is a sequence of one or more pipelines separated by `&&' or
`||'.  If two pipelines are separated by `&&', the second pipeline is
executed only if the first is successful (returns a zero value).  If
two pipelines are separated by `||', the second is executed only if the
first is unsuccessful (returns a nonzero value).

A "list" is a sequence of one or more sublists separated by, and
optionally terminated by, `;', `&', or a newline.  Normally the shell
waits for each list to finish before executing the next one.  If a list
is terminated by a `&', the shell executes it in the background, and
does not wait for it to finish.

Complex Commands
================

A "complex command" is one of the following:

`for NAME [ in WORD ... ]'
`do LIST'
`done'
     Expand the list of WORDs, and set the parameter NAME to each of
     them in turn, executing LIST each time.  If the `in WORD' is
     omitted, use the positional parameters instead of the WORDs.

`for NAME [ in WORD ... ] ; SUBLIST'
     This is a shorthand for `for'.  Though it may cause confusion, it
     is included for convenience; its use in scripts is discouraged,
     unless SUBLIST is a command of the form { LIST }.

`foreach NAME ( WORD ... )'
`LIST'
`end'
     Another form of `for'.

`for NAME in WORD ...'
`{'
`LIST'
`}'
     Another form of `for'.

`for NAME ( WORD ... ) {'
`LIST'
`}'
     Another form of `for'.

`for NAME ( WORD ... ) SUBLIST'
     Another form of `for'.

`select NAME [ in WORD ... ]'
`do LIST'
`done'
     Print the set of WORDs, each preceded by a number.  If the `in
     WORD' is omitted, use the positional parameters.  The `PROMPT3'
     prompt is printed and a line is read from standard input.  If this
     line consists of the number of one of the listed WORDs, then the
     parameter NAME is set to the WORD corresponding to this number.
     If this line is empty, the selection list is printed again.
     Otherwise, the value of the parameter NAME is set to null.  The
     contents of the line read from standard input is saved in the
     parameter `REPLY'.  LIST is executed for each selection until a
     break or end-of-file is encountered.

`select NAME [ in WORD ] ; SUBLIST'
     A short form of `select'.

`case WORD in [ PATTERN ) LIST ;; ] ... esac'
     Execute the LIST associated with the first PATTERN that matches
     WORD, if any.  The form of the patterns is the same as that used
     for filename generation.  See Filename Generation.

`case WORD { [ PATTERN ) LIST ;; ] ... }'
     Another form of `case'.

`if LIST'
`then LIST'
`[ elif LIST ; then LIST ] ...'
`[ else LIST ]'
`fi'
     The `if LIST' is executed, and, if it returns a zero exit status,
     the `then LIST' is executed.  Otherwise, the `elif LIST' is
     executed and, if its value is zero, the `then LIST' is executed.
     If each `elif LIST' returns nonzero, the `else LIST' is executed.

`if ( LIST ) SUBLIST'
     A short form of `if'.

`if ( LIST ) {'
`LIST'
`} elif ( LIST ) {'
`LIST'
`} ... else {'
`LIST'
`}'
     An alternate form of `if'.  The parentheses surrounding LIST can
     be omitted if the only command in the list is a conditional
     expression of the form `[[ EXP ]]'.  See Conditional Expressions.

`while LIST'
`do LIST'
`done'
     Execute the `do LIST' as long as the `while LIST' returns a zero
     exit status.

`while ( LIST ) {'
`LIST'
`}'
     An alternate form of `while'.

`until LIST'
`do LIST'
`done'
     Execute the `do LIST' as long as the `until LIST' returns a
     nonzero exit status.

`repeat WORD'
`do LIST'
`done'
     WORD is expanded and treated as an arithmetic expression, which
     must evaluate to a number N.  LIST is then executed N times.

`repeat WORD SUBLIST'
     This is a short form of `repeat'.

`( LIST )'
     Execute LIST in a subshell.

`{ LIST }'
     Execute LIST.

`function WORD [ () ] ... { LIST }'
`WORD ... () { LIST }'
`WORD ... () SUBLIST'
     Define a function which is referenced by any one of WORD.
     Normally, only one WORD is provided; multiple WORDs are usually
     only useful for setting traps.  The body of the function is the
     LIST between the `{' and `}'.  See Functions.

`time [ PIPELINE ]'
     The PIPELINE is executed, and timing statistics are reported on
     the standard error in the form specified by the `TIMEFMT'
     parameter.  If PIPELINE is omitted, print statistics about the
     shell process and its children.

`[[ EXP ]]'
     Evaluates the conditional expression EXP and return a zero exit
     status if it is true.  See Conditional Expressions, for a
     description of EXP.

Reserved Words
==============

The following words are recognized as "reserved words" when used as the
first word of a command unless quoted or removed using the `unalias'
builtin:

`do' `done' `esac' `then' `elif' `else' `fi' `for' `case' `if' `while'
`function' `repeat' `time' `until' `exec' `command' `select' `coproc'
`noglob' `-' `nocorrect' `foreach' `end'

Comments
========

In noninteractive shells, or in interactive shells with the
`INTERACTIVE_COMMENTS' option set, a word beginning with the third
character of the `HISTCHARS' parameter (`#' by default) causes that
word and all the following characters up to a newline to be ignored.

Aliasing
========

Every token in the shell input is checked to see if there is an alias
defined for it.  If so, it is replaced by the text of the alias if it is
in command position (if it could be the first word of a simple command),
or if the alias is global.  If the text ends with a space, the next word
in the shell input is treated as though it were in command position for
purposes of alias expansion.  An alias is defined using the `alias'
builtin; global aliases may be defined using the `-g' option to that
builtin.

Alias substitution is done on the shell input before any other
substitution except history substitution.  Therefore, if an alias is
defined for the word `foo', alias substitution may be avoided by
quoting part of the word, e.g. `\foo'.  But there is nothing to prevent
an alias being defined for `\foo' as well.

Quoting
=======

A character may be "quoted" (that is, made to stand for itself) by
preceding it with a `\'.  `\' followed by a newline is ignored.  All
characters enclosed between a pair of single quotes (`''') are quoted,
except the first character of `HISTCHARS' (`!' by default).  A single
quote cannot appear within single quotes.  Inside double quotes (`""'),
parameter and command substitution occurs, and `\' quotes the
characters `\', ``', `"', and `$'.

Expansion
*********

Expansion is performed on the command line after it has been parsed.
The types of expansions performed are "filename expansion", "process
substitution", "parameter expansion", "command substitution",
"arithmetic expansion", "brace expansion", and "filename generation".

Filename Expansion
==================

Each word is checked to see if it begins with an unquoted `~'.  If it
does, then the word up to a `/' is checked to see if it matches the
name of a named directory.  If so, then the `~' and the matched portion
are replaced with the value of the named directory.  A `~' by itself or
followed by a `/' is replaced by the value of the `HOME' parameter.  A
`~' followed by a `+' or a `-' is replaced by the value of `PWD' or
`OLDPWD', respectively.

Named directories are typically login directories for users on the
system.  They may also be defined if the text after the `~' is the name
of a string shell parameter whose value begins with a `/'.  In certain
circumstances (in prompts, for instance), when the shell prints a path,
the path is checked to see if it has a named directory as its prefix.
If so, then the prefix portion is replaced with a `~' followed by the
name of the directory.  The longest match is preferred.

If a word begins with an unquoted `=' and the `NO_EQUALS' option is not
set, the remainder of the word is taken as the name of a command or
alias.  If a command exists by that name, the word is replaced by the
full pathname of the command.  If an alias exists by that name, the
word is replaced with the text of the alias.  Otherwise the word is
checked up to a `/' to see if it is a number or a `-'.  If so, the
matched portion is replaced with the N'th directory in the directory
stack, where N is the number matched, or the last directory in the
directory stack if a `-' is matched.

Filename expansion is performed on the right hand side of a parameter
assignment, including those appearing after commands of the `typeset'
family.  In this case, the right hand side will be treated as a
colon-separated list in the manner of `PATH', so that a `~' or `='
following a `:' is eligible for expansion.  All such behaviour can be
disabled by quoting the `~', `=', or the whole expression (but not
simply the colon); the `NO_EQUALS' option is also respected.

If the option `MAGIC_EQUAL_SUBST' is set, any unquoted shell argument
of the form `IDENTIFIER=EXPRESSION' becomes eligible for file expansion
as described in the previous paragraph.  Quoting the first `=' also
inhibits this.

Process Substitution
====================

Each command argument of the form `<(LIST)', `>(LIST)' or `=(LIST)' is
subject to process substitution.  In the case of the `<' and `>' forms,
the shell will run process LIST asynchronously, connected to a named
pipe (FIFO).  The name of this pipe will become the argument to the
command.  If the form with `>' is selected then writing to this file
will provide input for LIST.  If `<' is used, then the file passed as
an argument will be a named pipe connected to the output of the LIST
process.  For example,

   `paste <(cut -f1 FILE1) <(cut -f3 FILE2) | tee >(PROCESS1)
>(PROCESS2) >/dev/null'

`cut's fields 1 and 3 from the files FILE1 and FILE2 respectively,
`paste's the results together, and sends it to the processes PROCESS1
and PROCESS2.  Note that the file, which is passed as an argument to
the command, is a system pipe so programs that expect to `lseek(2)' on
the file will not work.  Also note that the previous example can be
more compactly and efficiently written as:

   `paste <(cut -f1 FILE1) <(cut -f3 FILE2) >>(PROCESS1) >>(PROCESS2)'

The shell uses pipes instead of FIFOs to implement the latter two
process substitutions in the above example.

If `=' is used, then the file passed as an argument will be the name of
a temporary file containing the output of the LIST process.  This may
be used instead of the `<' form for a program that expects to
`lseek(2)' on the input file.

Parameter Expansion
===================

The character `$' is used to introduce parameter expansions.  See
Parameters, for a description of parameters.

`${NAME}'
     The value, if any, of the parameter NAME is substituted.  The
     braces are required if NAME is followed by a letter, digit, or
     underscore that is not to be interpreted as part of its name.  If
     NAME is an array parameter, then the values of each element of
     NAME is substituted, one element per word.  Otherwise, the
     expansion results in one word only; no word splitting is done on
     the result.

`${+NAME}'
     If NAME is the name of a set parameter, then substitute 1,
     otherwise substitute 0.

`${NAME:-WORD}'
     If NAME is set and is non-null then substitute its value;
     otherwise substitute WORD.

`${NAME:=WORD}'
     If NAME is unset or is null then set it to WORD; the value of the
     parameter is then substituted.

`${NAME:?WORD}'
     If NAME is set and is non-null, then substitute its value;
     otherwise, print WORD and exit from the shell.  If WORD is
     omitted, then a standard message is printed.

`${NAME:+WORD}'
     If NAME is set and is non-null then substitute WORD; otherwise
     substitute nothing.

`${NAME#PATTERN}'
`${NAME##PATTERN}'
     If the PATTERN matches the beginning of the value of NAME, then
     substitute the value of NAME with the matched portion deleted;
     otherwise, just substitute the value of NAME.  In the first form,
     the smallest matching pattern is preferred; in the second form,
     the largest matching pattern is preferred.

`${NAME%PATTERN}'
`${NAME%%PATTERN}'
     If the PATTERN matches the end of the value of NAME, then
     substitute the value of NAME with the matched portion deleted;
     otherwise, just substitute the value of NAME.  In the first form,
     the smallest matching pattern is preferred; in the second form, the
     largest matching pattern is preferred.

`${#SPEC}'
     If SPEC is one of the above substitutions, substitute the length
     in characters of the result instead of the result itself.  If SPEC
     is an array expression, substitute the number of elements of the
     result.

`${^SPEC}'
     Toggle the value of the `RC_EXPAND_PARAM' option for the evaluation
     of SPEC.  When this option is set, array expansions of the form
     `foo${xx}bar', where the parameter `xx' is set to `(a b c)', are
     substituted with `fooabar foobbar foocbar' instead of the default
     `fooa b cbar'.

`${=SPEC}'
     Toggle the value of the `SH_WORD_SPLIT' option for the evaluation
     of SPEC.  When this option is set, parameter values are split into
     separate words using `IFS' as a delimiter before substitution.
     This is done by default in most other shells.

`${~SPEC}'
     Toggle the value of the `CSH_JUNKIE_TILDE' option for the
     evaluation of SPEC.  When this option is set, any `=' and `~'
     resulting from the substitution become eligible for filename
     expansion.

If the colon is omitted from one of the above expressions containing a
colon, then the shell only checks whether NAME is set or not, not
whether it is null.

If the opening brace is directly followed by an opening parenthesis the
string up to the matching closing parenthesis will be taken as a list
of flags, where the following flags are supported:

`o'
     The resulting words will be sorted in ascending order.

`O'
     The resulting words will be sorted in descending order.

`i'
     If given together with `o' or `O', makes the sort case-insensitive.

`L'
     Converts the result to all lowercase.

`U'
     Converts the result to all uppercase.

`C'
     Capitalizes the result.

`c'
     If using `${#NAME}' to count array elements, this flag makes it
     count characters instead (as if the elements were concatenated
     with spaces between them).

`w'
     Like `c', but works for strings and arrays and makes it count words
     (words are strings separated by white space or by the string given
     with the `s' flag).

`l:EXPR::STRING1::STRING2:'
     Specifies a left padding for the resulting words.  Each word will
     be right-justified in a field EXPR characters wide (truncated if
     needed), and any space to the left of the word will be filled with
     STRING1 (concatenated as often as needed), or spaces if STRING1 is
     not given.  If STRING2 is also given, this string will be placed
     exactly once directly to the left of the resulting word.  Any
     character can be used instead of the colon to enclose the arguments
     (or the pairs `(...)', `{...}', `[...]', or `<...>' can be used).

`r:EXPR::STRING1::STRING2:'
     Like `l', but for right padding.

`j:STRING:'
     If `SH_WORD_SPLIT' is set, the resulting words will be concatenated
     with STRING and then split again at the string given with the `s'
     flag.  If neither `j' nor `s' are given this will be done with
     spaces.  If only `j' is given, the string to separate words
     defaults to the string given with the `s' flag.

`s:STRING:'
     See above.

`S'
     All flags from here on are used with the `${...#...}' and
     `${...%...}' forms.  The `S' flag applies the search to substrings
     as well as to the beginnings and ends of strings.

`I:EXPR:'
     Assuming EXPR evaluates to N, returns the N'th match.

`M'
     Include the matched portion in the result.

`R'
     Include the unmatched portion in the result (the Rest).

`B'
     Include the index of the beginning of the match in the result.

`E'
     Include the index of the end of the match in the result.

`N'
     Include the length of the match in the result.

Command Substitution
====================

A command enclosed in parentheses preceded by a dollar sign, like so:
`$(...)' or quoted with grave accents: ``...`' is replaced with its
standard output.  If the substitution is not enclosed in double quotes,
the output is broken into words using the `IFS' parameter.  The
substitution `$(cat foo)' may be replaced by the equivalent but faster
`$(<foo)'.

Arithmetic Expansion
====================

A string of the form `$[EXP]' is substituted with the value of the
arithmetic expression EXP.  EXP is treated as if it were within single
quotes.  See Arithmetic Evaluation.

Brace Expansion
===============

A string of the form `foo{xx,yy,zz}bar' is expanded to the individual
words `fooxxbar',
`fooyybar', and `foozzbar'.  Left-to-right order is preserved.  This
construct may be nested.  Malformed brace expansion expressions,
including expressions without a comma, are left unchanged by the shell.

An expression of the form `{x-y}', where `x' and `y' are single
characters, is expanded to every character between `x' and `y',
inclusive.

Filename Generation
===================

If a word contains an unquoted instance of one of the characters `*',
`|', `<', `[', or `?', it is regarded as a pattern for filename
generation, unless the `NO_GLOB' option is set.  If the `EXTENDED_GLOB'
option is set, the `^' and `#' characters also denote a pattern;
otherwise they are not treated specially by the shell.  The word is
replaced with a list of sorted filenames that match the pattern.  If no
matching pattern is found, the shell gives an error message, unless the
`NULL_GLOB' option is set, in which case the word is deleted; or unless
the `NO_NOMATCH' option is set, in which case the word is left
unchanged.  In filename generation, the character `/' must be matched
explicitly; also, a `.' must be matched explicitly at the beginning of
a pattern or after a `/', unless the `GLOB_DOTS' option is set.  No
filename generation pattern matches the files `.' or `..'.  In other
instances of pattern matching, the `/' and `.' are not treated
specially.

`*'
     Matches any string, including the null string.

`?'
     Matches any character.

`[...]'
     Matches any of the enclosed characters.

`[^...]'
     Matches any character except the enclosed characters.

`<x-y>'
     Matches any number in the range `x' to `y', inclusive.  If `x' is
     omitted, the number must be less than or equal to `y'.  If `y' is
     omitted, the number must be greater than or equal to `x'.  A
     pattern of the form `<->' or simply `<>' matches any number.

`^x'
     Matches anything except the pattern `x'.

`x|y'
     Matches either `x' or `y'.

`x#'
     Matches zero or more occurrences of the pattern `x'.

`x##'
     Matches one or more occurrences of the pattern `x'.

Parentheses may be used for grouping.  Note that the `|' character must
be within parentheses, so that the lexical analyzer does not think it
is a pipe character.  Also note that `/' has a higher precedence than
`^'; that is:

   `ls ^foo/bar'

will search directories in `.' except `./foo' for a file named `bar'.

A pathname component of the form `(FOO/)#' matches a path consisting of
zero or more directories matching the pattern FOO.  As a shorthand,
`**/' is equivalent to `(*/)#'.  Thus:

   `ls (*/)#bar'

or

   `ls **/bar'

does a recursive directory search for files named `bar'.

If used for filename generation, a pattern may contain an exclusion
specifier.  Such patterns are of the form `PAT1~PAT2'.  This pattern
will generate all files matching PAT1, but which do not match PAT2.
For example, `*.c~lex.c' will match all files ending in `.c', except
the file `lex.c'.

Patterns used for filename generation may also end in a list of
qualifiers enclosed in parentheses.  The qualifiers specify which
filenames that otherwise match the given pattern will be inserted in the
argument list.  A qualifier may be any one of the following:

`/'
     Directories

`.'
     Plain files

`@'
     Symbolic links

`='
     Sockets

`p'
     Named pipes (FIFOs)

`*'
     Executable plain files (0100)

`%'
     Device files (character or block special)

`%b'
     Block special files

`%c'
     Character special files

`r'
     Readable files (0400)

`w'
     Writable files (0200)

`x'
     Executable files (0100)

`R'
     World-readable files (0004)

`W'
     World-writable files (0002)

`X'
     World-executable files (0001)

`s'
     Setuid files (04000)

`S'
     Setgid files (02000)

`dDEV'
     Files on the device DEV

`l[+-]CT'
     Files having a link count less than (`-'), more than (`+'), or
     equal to CT.

`U'
     Files owned by the effective user id.

`G'
     Files owned by the effective group id.

`uID'
     Files owned by user ID if ID is a number.  If not, the character
     after the `u' will be used as a separator and the string between
     it and the next matching separator (`(', `[', `{', and `<' match
     `)', `]', `}', and `>' respectively; any other character matches
     itself) will be taken as a user name and translated into the
     corresponding user id (e.g.  `u:foo:' or `u[foo]' for user `foo').

`gID'
     Like `uID' but with group ids or names.

`a[+-]N'
     Files accessed within last N days (`-'), more than N days ago
     (`+'), or exactly N days ago.

`m[+-]N'
     Files modified within last N days (`-'), more than N days ago
     (`+'), or exactly N days ago.

`c[+-]N'
     Files whose inode changed within last N days (`-'), more than N
     days ago (`+'), or exactly N days ago.  If any of the flags `a',
     `m', or `c' is directly followed by a `M', `w', `h', or `m' (e.g.
     `mh+5') the check is performed in units of months (of 30 days),
     weeks, hours, or minutes respectively.

`L[+-]N'
     Files less than N bytes (`-'), more than N bytes (`+'), or exactly
     N bytes in length.

`^'
     Negates all qualifiers following it.

`-'
     Toggles between making the qualifiers work on symbolic links (the
     default), and the files they point to.

`M'
     Sets the `MARK_DIRS' option for the current pattern.

`T'
     Appends a trailing qualifier mark to the file names, analogous to
     the `LIST_TYPES', for the current pattern (overrides `M').

`N'
     Sets the `NULL_GLOB' option for the current pattern.

`D'
     Sets the `GLOB_DOTS' option for the current pattern.

More than one of these lists can be combined, separated by commas; the
whole list matches if at least one of the sublists matches (they are
or'ed, the qualifiers in the sublists are and'ed).  A `/' at the end of
a pattern is equivalent to `(/)'.

If a `:' appears in a qualifier list, the remainder of the expression
in parentheses is interpreted as a modifier (see Modifiers).  Note
that each modifier must be introduced by a separate `:'.  Note also
that the result after modification does not have to be an existing
file.  The name of any existing file can be followed by a modifier of
the form `(:...)' even if no filename generation is performed.

Thus:

   `ls *(-/)'

lists all directories and symbolic links that point to directories, and

   `ls *(%W)'

lists all world-writable device files in the current directory, and

   `ls *(W,X)'

lists all files in the current directory that are world-writable or
world-executable, and

   `echo /tmp/foo*(u0^@:t)'

outputs the basename of all root-owned files beginning with the string
`foo' in `/tmp', ignoring symlinks, and

   `ls *.*~(lex|parse).[ch](^D^l1)'

lists all files having a link count of one whose names contain a dot
(but not those starting with a dot, since `GLOB_DOTS' is explicitly
switched off) except for `lex.c', `lex.h', `parse.c', and `parse.h'.

Redirection
***********

Before a command is executed, its input and output may be redirected.
The following may appear anywhere in a simple command or may precede or
follow a complex command.  Substitution occurs before WORD is used
except as noted below.  If the result of substitution on WORD produces
more than one filename, redirection occurs for each separate filename
in turn.

`<WORD'
     Open file WORD as standard input.

`>WORD'
     Open file WORD as standard output.  If the file does not exist
     then it is created.  If the file exists, and the `NO_CLOBBER'
     option is set, this causes an error; otherwise, it is truncated to
     zero length.

`>!WORD'
     Same as `>', except that the file is truncated to zero length if it
     exists, even if `NO_CLOBBER' is set.

`>>WORD'
     Open file WORD as standard output.  If the file exists then output
     is appended to it.  If the file does not exist, and the
     `NO_CLOBBER' option is set, this causes an error; otherwise, the
     file is created.

`>>!WORD'
     Same as `>>', except that the file is created if it does not exist,
     even if `NO_CLOBBER' is set.

`<<[-]WORD'
     The shell input is read up to a line that is the same as WORD, or
     to an end-of-file.  No parameter substitution, command
     substitution or filename generation is performed on WORD.  The
     resulting document, called a "here-document", becomes the standard
     input.  If any character of WORD is quoted with single or double
     quotes or a `\', no interpretation is placed upon the characters
     of the document.  Otherwise, parameter and command substitution
     occurs, `\' followed by a newline is removed, and `\' must be used
     to quote the characters `\', `$', ``', and the first character of
     WORD.  If `<<-' is used, then all leading tabs are stripped from
     WORD and from the document.

`<<<WORD'
     Open a file containing WORD, after expansion, as standard input.

`<&DIGIT'
     The standard input is duplicated from file descriptor DIGIT (see
     `dup(2)').  Similarly for standard output using `>&DIGIT'.

`>&WORD'
     Same as `>WORD 2>&1'.

`>>&WORD'
     Same as `>>WORD 2>&1'.

`<&-'
     Close the standard input.

`>&-'
     Close the standard output.

`<&p'
     The input from the coprocess is moved to the standard input.

`>&p'
     The output to the coprocess is moved to the standard output.

If one of the above is preceded by a digit, then the file descriptor
referred to is that specified by the digit (instead of the default 0 or
1).  The order in which redirections are specified is significant.  The
shell evaluates each redirection in terms of the (FILE DESCRIPTOR,
FILE) association at the time of evaluation.  For example:

   `... 1>FNAME 2>&1'

first associates file descriptor 1 with file FNAME.  It then associates
file descriptor 2 with the file associated with file descriptor 1 (that
is, FNAME).  If the order of redirections were reversed, file
descriptor 2 would be associated with the terminal (assuming file
descriptor 1 had been) and then file descriptor 1 would be associated
with file FNAME.

If the user tries to open a file descriptor for writing more than once,
the shell opens the file descriptor as a pipe to a process that copies
its input to all the specified outputs, similar to `tee(1)'.  Thus:

   `date >foo >bar'

writes the date to two files, named `foo' and `bar'.  Note that a pipe
is an implicit indirection; thus

   `date >foo | cat'

writes the date to the file `foo', and also pipes it to `cat'.

If the user tries to open a file descriptor for reading more than once,
the shell opens the file descriptor as a pipe to a process that copies
all the specified inputs to its output in the order specified, similar
to `cat(1)'.  Thus

   `sort <foo <fubar'

or even

   `sort <f{oo,ubar}'

is equivalent to `cat foo fubar | sort'.  Note that a pipe is an
implicit indirection; thus

   `cat bar | sort <foo'

is equivalent to `cat bar foo | sort' (note the order of the inputs).

If a simple command consists of one or more redirection operators and
zero or more parameter assignments, but no command name, the command
`cat' is assumed.  Thus

   `< file'

prints the contents of `file'.

If a command is followed by `&' and job control is not active, then the
default standard input for the command is the empty file `/dev/null'.
Otherwise, the environment for the execution of a command contains the
file descriptors of the invoking shell as modified by input/output
specifications.

Command Execution
*****************

If a command name contains no slashes, the shell attempts to locate it.
If there exists a shell function by that name, the function is invoked
as described below (see Functions.).  If there exists a shell
builtin by that name, the builtin is invoked.

Otherwise, the shell searches each element of `path' for a directory
containing an executable file by that name.  If the search is
unsuccessful, the shell prints an error message and returns a nonzero
exit status.

If execution fails because the file is not in executable format, and the
file is not a directory, it is assumed to be a shell script.  `/bin/sh'
is spawned to execute it.  If the program is a file beginning with
`#!', the remainder of the first line specifies an interpreter for the
program.  The shell will execute the specified interpreter on operating
systems that do not handle this executable format in the kernel.

Functions
*********

The `function' reserved word is used to define shell functions.  Shell
functions are read in and stored internally.  Alias names are resolved
when the function is read.  Functions are executed like commands with
the arguments passed as positional parameters.

Functions execute in the same process as the caller and share all files
and the present working directory with the caller.  A trap on `EXIT'
set inside a function is executed after the function completes in the
environment of the caller.

The `return' builtin is used to return from function calls.

Function identifiers can be listed with the `functions' builtin.
Functions can be undefined with the `unfunction' builtin.

The following functions, if defined, have special meaning to the shell:

`chpwd'
     Executed whenever the current working directory is changed.

`precmd'
     Executed before each prompt.

`periodic'
     If the parameter `PERIOD' is set, this function is executed every
     `PERIOD' seconds, just before a prompt.

`TRAPXXX'
     If defined and non-null, this function will be executed whenever
     the shell catches a signal `SIGXXX', where XXX is a signal name as
     specified for the `kill' builtin (see Shell Builtin Commands.).
     In addition, `TRAPZERR' is executed whenever a
     command has a non-zero exit status, `TRAPDEBUG' is executed after
     each command, and `TRAPEXIT' is executed when the shell exits, or
     when the current function exits if defined inside a function.  If
     a function of this form is defined and null, the shell and
     processes spawned by it will ignore `SIGXXX'.

Jobs & Signals
**************

If the `MONITOR' option is set, an interactive shell associates a "job"
with each pipeline.  It keeps a table of current jobs, printed by the
`jobs' command, and assigns them small integer numbers.  When a job is
started asynchronously with `&', the shell prints a line which looks
like:

   `[1] 1234'

indicating that the job which was started asynchronously was job number
1 and had one (top-level) process, whose process id was 1234.

If you are running a job and wish to do something else you may hit the
key `^Z' (control-Z) which sends a `TSTP' signal to the current job.
The shell will then normally indicate that the job has been
"suspended", and print another prompt.  You can then manipulate the
state of this job, putting it into the background with the `bg'
command, or run some other commands and then eventually bring the job
back into the foreground with the foreground command `fg'.  A `^Z'
takes effect immediately and is like an interrupt in that pending
output and unread input are discarded when it is typed.

A job being run in the background will suspend if it tries to read from
the terminal.  Background jobs are normally allowed to produce output,
but this can be disabled by giving the command `stty tostop'.  If you
set this tty option, then background jobs will suspend when they try to
produce output, just as they do when they try to read input.

There are several ways to refer to jobs in the shell.  A job can be
referred to by the process id of any process of the job or by one of the
following:

`%NUMBER'
     The job with the given number.

`%STRING'
     Any job whose command line begins with STRING.

`%?STRING'
     Any job whose command line contains STRING.

`%%'
     Current job.

`%+'
     Equivalent to `%%'.

`%-'
     Previous job.

The shell learns immediately whenever a process changes state.  It
normally informs you whenever a job becomes blocked so that no further
progress is possible.  If `notify' is not set, it waits until just
before it prints a prompt before it informs you.

When the monitor mode is on, each background job that completes triggers
any trap set for `CHLD'.

When you try to leave the shell while jobs are running or suspended, you
will be warned that `You have suspended (running) jobs'.  You may use
the `jobs' command to see what they are.  If you do this or immediately
try to exit again, the shell will not warn you a second time; the
suspended jobs will be terminated, and the running jobs will be sent a
`SIGHUP' signal.  To avoid having the shell terminate the running jobs,
either use the `nohup(1)' command or the `disown' builtin (see Shell Builtin Commands.).

The `INT' and `QUIT' signals for an invoked command are ignored if the
command is followed by `&' and the job `monitor' option is not active.
Otherwise, signals have the values inherited by the shell from its
parent (but Functions, for the `TRAPXXX' special functions).

History
*******

History substitution allows you to use words from previous command lines
in the command line you are typing.  This simplifies spelling
corrections and the repetition of complicated commands or arguments.
Command lines are saved in the history list, the size of which is
controlled by the `HISTSIZE' variable.  The most recent command is
retained in any case.  A history substitution begins with a `!' and may
occur anywhere on the command line; history substitutions do not nest.
The `!' can be escaped with `\' to suppress its special meaning.
Single or double quotes will *not* work for this.

Input lines containing history substitutions are echoed on the terminal
after being expanded, but before any other substitutions take place or
the command gets executed.

Event Designators
=================

An event designator is a reference to a command-line entry in the
history list.

`!'
     Start a history substitution, except when followed by a blank,
     newline, `=', or `('.

`!!'
     Refer to the previous command.  By itself, this substitution
     repeats the previous command.

`!n'
     Refer to command line N.

`!-n'
     Refer to the current command line minus N.

`!str'
     Refer to the most recent command starting with STR.

`!?STR[?]'
     Refer to the most recent command containing STR.

`!#'
     Refer to the current command line typed in so far.

`!{...}'
     Insulate a history reference from adjacent characters (if
     necessary).

Word Designators
================

A word designator indicates which word or words of a given command line
will be included in a history reference.  A `:' separates the event
specification from the word designator.  It can be omitted if the word
designator begins with a `,', `$', `*', `-' or `%'.  Word designators
include:

`0'
     The first input word (command).

`N'
     The N'th argument.

`^'
     The first argument, that is, `1'.

`$'
     The last argument.

`%'
     The word matched by (the most recent) `?STR' search.

`X-Y'
     A range of words;  `-Y' abbreviates `0-Y'.

`*'
     All the arguments, or a null value if there is just one word in the
     event.

`X*'
     Abbreviates `X-$'.

`X'
     Like `X*' but omitting word `$'.

Note that a `%' word designator will only work when used as `!%',
`!:%', or `!?STR?:%', and only when used after a `?!' substitution.
Anything else will result in an error, although the error may not be
the most obvious one.

Modifiers
=========

After the optional word designator, you can add a sequence of one or
more of the following modifiers, each preceded by a `:'.  These
modifiers also work on the result of filename and parameter expansion.

`h'
     Remove a trailing pathname component, leaving the head.

`r'
     Remove a trailing suffix of the form `.XXX', leaving the basename.

`e'
     Remove all but the suffix.

`t'
     Remove all leading pathname components, leaving the tail.

`&'
     Repeat the previous substitution.

`g'
     Apply the change to the first occurrence of a match in each word,
     by prefixing the above (for example, `g&').

`p'
     Print the new command but do not execute it.

`q'
     Quote the substituted words, escaping further substitutions.

`x'
     Like `q', but break into words at each blank.

`l'
     Convert the words to all lowercase.

`u'
     Convert the words to all uppercase.

`f'
     Repeats the immediately-following (without a colon) modifier until
     the resulting word doesn't change any more.  This modifier and the
     following four only work with parameter and filename expansion.

`F:EXPR:'
     Like `f', but repeats only N times if the expression EXPR
     evaluates to N.  Any character can be used instead of the `:',
     with the exception that if `(', `[', or `{' is used as the opening
     delimiter, the closing delimiter must be `)', `]', or `}'
     respectively.

`w'
     Makes the immediately-following modifier work on each word in the
     string.

`W:SEP:'
     Like `w', but words are considered to be the parts of the string
     that are separated by SEP.  Delimiters are handled as in `F' above.

`s/L/R[/]'
     Substitute R for L.

     Unless preceded by a `g', the substitution is done only for the
     first string that matches L.

     The left-hand side of substitutions are not regular expressions,
     but character strings.  Any character can be used as the delimiter
     in place of `/'.  A backslash quotes the delimiter character.  The
     character `&', in the right-hand side, is replaced by the text
     from the left-hand side.  The `&' can be quoted with a backslash.
     A null L uses the previous string either from a L or from a
     contextual scan string S from `!?S'.  You can omit the rightmost
     delimiter if a newline immediately follows R; the rightmost `?' in
     a context scan can similarly be omitted.

By default, a history reference with no event specification refers to
the same line as the last history reference on that command line, unless
it is the first history reference in a command.  In that case, a history
reference with no event specification always refers to the previous
command.  However, if the option `CSH_JUNKIE_HISTORY' is set, then a
history reference with no event specification will ALWAYS refer to the
previous command.  For example, `!!:1' will always refer to the first
word of the previous command and `!!$' will always refer to the last
word of the previous command.  If `CSH_JUNKIE_HISTORY' is set, then
`!:1' and `!$' will function in the same manner as `!!:1' and `!!$',
respectively.  However, if `CSH_JUNKIE_HISTORY' is unset, then `!:1' and
`!$' will refer to the first and last words respectively of the last
command referenced on the current command line.  However, if they are
the first history reference on the command line, then they refer to the
previous command.

The character sequence `^foo^bar' repeats the last command, replacing
the string `foo' with the string `bar'.

If the shell encounters the character sequence `!"' in the input, the
history mechanism is temporarily disabled until the current list is
fully parsed.  The `!"' is removed from the input, and any subsequent
`!' characters have no special significance.

A less convenient but more comprehensible form of command history
support is provided by the `fc' builtin (see Shell Builtin Commands.).

Arithmetic Evaluation
*********************

An ability to perform integer arithmetic is provided with the builtin
`let'.  Evaluations are performed using *long* arithmetic.  Constants
are of the form `[BASE#]N' where BASE is a decimal number between two
and thirty-six representing the arithmetic base and N is a number in
that base (for example, `16#ff' is 255 in hexadecimal).  If BASE is
omitted then base 10 is used.  For backwards compatibility the form
`[16]ff' is also accepted.

An arithmetic expression uses nearly the same syntax, precedence, and
associativity of expressions in C.  The following operators are
supported (listed in decreasing order of precedence):

`+ - ! ~ ++ --'
     Unary plus/minus, logical NOT, complement, {pre,post}{in,de}crement

`&'
     Logical AND

`^'
     Logical XOR

`|'
     Logical OR

`* / % **'
     Multiplication, division, remainder, exponentiation

`+ -'
     Addition, subtraction

`<< >>'
     Logical shift left, shift right

`< > <= >='
     Comparison

`== !='
     Equality and inequality

`&&'
     Boolean AND

`|| ^^'
     Boolean OR, XOR

`? :'
     Ternary operator

`= += -= *= /= %= &= ^= |= <<= >>= &&= ||= ^^= **='
     Assignment

`,'
     Comma operator

The operators `&&', `||', `&&=', and `||=' are short-circuiting, and
only one of the latter two expressions in a ternary operator is
evaluated.  Note the precedence of the logical AND, OR, and XOR
operators.

An expression of the form `#\x' where `x' is any character gives the
ASCII value of this character.  An expression of the form `#foo' gives
the ASCII value of the first character of the value of the parameter
`foo'.

Named parameters can be referenced by name within an arithmetic
expression without using the parameter substitution syntax, but if it is
an array with a subscript the leading `$' is needed.

An internal integer representation of a named parameter can be specified
with the `integer' builtin.  Arithmetic evaluation is performed on the
value of each assignment to a named parameter declared integer in this
manner.

Since many of the arithmetic operators require quoting, an alternative
form of the `let' command is provided.  For any command which begins
with a `((', all the characters until a matching `))' are treated as a
quoted expression.  More precisely, `(( ... ))' is equivalent to `let
"..."'.