.ds ' \s+4\v@.3m@\'\v@-.3m@\s-4
.ds ` \s+4\v@.3m@\`\v@-.3m@\s-4
.tl @Copyright (c) 1984, 1985, 1986, 1987@@AT&T All Rights Reserved@
.tl @Copyright (c) 1984, 1985, 1986, 1987@@AT&T All Rights Reserved@
sh, rsh \- shell, the standard/restricted command programming language
is a command programming language
that executes commands read from a terminal
is a restricted version of the standard command interpreter
it is used to set up login names and execution environments whose
capabilities are more controlled than those of the standard shell.
for the meaning of arguments to the shell.
is one of the following characters:
\f3; & ( ) \(bv < > new-line space tab\fP
is a sequence of letters, digits, or underscores
starting with a letter or underscore.
Identifiers are used as names for
separated by one or more non-quoted
which may be preceded by a parameter assignment list.
The first word specifies the name of the command to
Except as specified below,
the remaining words are passed as arguments
The command name is passed as argument 0
of a simple-command is its exit status
if it terminates normally, or (octal) 200+\f2status\^\fP if
it terminates abnormally (see
is a sequence of one or more
The standard output of each command but the last
to the standard input of the next command.
Each command is run as a separate process;
the shell waits for the last command to terminate.
The exit status of a pipeline is the exit
status of the last command.
is a sequence of one or more
and optionally terminated by
which is lower than that of
also have equal precedence.
causes sequential execution of the preceding pipeline; an ampersand
causes asynchronous execution of the preceding pipeline (i.e., the shell does
wait for that pipeline to finish).
causes asynchronous execution of the preceding command or pipeline
with a two-way pipe established to the parent shell.
The standard input and output of the spawned command
can be written to and read from by the parent Shell
Only one such command can be active
following it to be executed only if the preceding
returns a zero (non-zero) value.
An arbitrary number of new-lines may appear in a
is either a simple-command
the value returned by a command is that of the
last simple-command executed in the command.
\f3for\fP \f2identifier\^\fP \*(OK \f3in\fP \f2word\^\fP .\|.\|. \*(CK \f3do\fP \f2list\^\fP \f3done\fP
command executes the \f3do\fP \f2list\^\fP once for each positional parameter
.I "Parameter Substitution\^"
Execution ends when there are no more words in the list.
\f3select\fP \f2identifier\^\fP \*(OK \f3in\fP \f2word\^\fP .\|.\|. \*(CK \f3do\fP \f2list\^\fP \f3done\fP
command prints on standard error (file descriptor 2), the set of
each preceded by a number.
.I "Parameter Substitution\^"
and a line is read from the standard input.
If this line consists of the number
then the value of the parameter
corresponding to this number.
If this line is empty the selection list is
Otherwise the value of the parameter
The contents of the line read from standard input is
is executed for each selection until a
\f3case\fP \f2word\^\fP \f3in\fP \*(OK \f2pattern\^\fP \*(OK \(bv \
\f2pattern\^\fP \*(CK .\|.\|. \f3)\fP \f2list\^\fP \f3;;\fP \*(CK .\|.\|. \f3esac\fP
associated with the first
The form of the patterns is
the same as that used for
file-name generation (see
.I "File Name Generation\^"
\f3if\fP \f2list\^\fP \f3then\fP \f2list\^\fP \*(OK \
\f3elif\fP \f2list\^\fP \f3then\fP \f2list\^\fP \*(CK .\|.\|. \
\*(OK \f3else\fP \f2list\^\fP \*(CK \f3f\&i\fP
following \f3if\fP is executed and,
returns a zero exit status, the
is executed and, if its value is zero,
command returns a zero exit status.
\f3while\fP \f2list\^\fP \f3do\fP \f2list\^\fP \f3done\fP
\f3until\fP \f2list\^\fP \f3do\fP \f2list\^\fP \f3done\fP
command repeatedly executes the
and, if the exit status of the last command in the list is zero, executes
otherwise the loop terminates.
command returns a zero exit status;
the loop termination test.
\f3(\fP\f2list\^\fP\f3)\fP
in a separate environment.
Note, that if two adjacent open parentheses are
needed for nesting, a space must be inserted to avoid
arithmetic evaluation as described below.
A parenthesized list used as a command argument denotes
.I "process substitution"
\f3{ \fP\f2list\^\fP\f3;}\fP
in order to be recognized.
\f3function\fP \f2identifier\^\fP \f3{\fP \f2list\^\fP \f3;}\fP
\f2identifier\^\fP \f3() {\fP \f2list\^\fP \f3;}\fP
Define a function which is referenced by
The body of the function is the
\f3time \fP\f2pipeline\^\fP
is executed and the elapsed time as well as
the user and system time are printed on standard error.
are only recognized as the first word of a command
.if n if then else elif fi case esac for while until do done { } function select time
.if t if then else elif fi case esac for while until do done { } function select time
causes that word and all the following characters up to a new-line
The first word of each command is replaced by the text of an
for this word has been defined.
name can be any non-special printable character,
but the rest of the characters
must be the same as for a valid
The replacement string can contain any
including the metacharacters listed above.
The first word of each command of the
replaced text will not be tested for additional aliases.
If the last character of the alias value is a
then the word following the alias will also be checked for alias
Aliases can be used to redefine special
builtin commands but cannot be used to redefine
the keywords listed above.
Aliases can be created, listed, and exported with the
command and can be removed with the
Exported aliases remain in effect for sub-shells
but must be reinitialized for separate invocations
not while they are executed.
for an alias to take effect
command has to be executed before
the command which references the alias is read.
Aliases are frequently used as a short hand for full path
An option to the aliasing facility allows the value of the alias
to be automatically set to the full pathname of
the corresponding command.
alias is defined the first time the corresponding command
is looked up and becomes undefined each time
subsequent reference will redefine the value.
Several tracked aliases are compiled into the shell.
command makes each command name which is a
are compiled into the shell
but can be unset or redefined:
.B "functions=\(fmtypeset \-f\(fm"
.B "history=\(fmfc \-l\(fm"
.B "integer=\(fmtypeset \-i\(fm"
.B "nohup=\(fmnohup \(fm"
.B "type=\(fmwhence \-v\(fm"
.B "hash=\(fmalias \-t\(fm"
After alias substitution is performed, 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 a user name in the
and the matched login name is replaced by the
login directory of the matched user.
If no match is found, the original text is left unchanged.
by itself, or in front of a
is replaced by the value of the
is replaced by the value of
In addition, the value of each
is checked to see if it begins with a
In either of these cases a
substitution is attempted.
.SS Command Substitution.
The standard output from a command enclosed in
parenthesis preceded by a dollar sign (
or a pair of grave accents (\^\f3\*`\^\*`\fP\^)
may be used as part or all
trailing new-lines are removed.
In the second (archaic) form, the string between the quotes is processed
for special quoting characters before the command is executed. (See
\^\f3$(\^cat file\^)\fP\^
can be replaced by the equivalent but faster
Command substitution of most special commands
that do not perform input/output redirection are
carried out without creating a separate process.
.SS Process Substitution.
This feature is only available on
versions of the UNIX operating system that support the
directory for naming open files.
Each command argument of the form
\f3(\fP\f2list\^\fP\f3)\fP,
\f3<(\fP\f2list\^\fP\f3)\fP,
\f3>(\fP\f2list\^\fP\f3)\fP
asynchronously connected to some file in
The name of this file will become the argument to the command.
is selected then writing on this file will provide input for
then the file passed as an argument will contain the output of the
\f3paste (cut \-f1\fP \f2file1\fP\f3) (cut \-f3\fP \f2file2\f3) | tee >(\fP\f2process1\fP\f3) >(\fP\f2process2\fP\f3)\fP
the results together, and
as well as putting it onto the standard output.
Note that the file, which is passed as an argument to the command,
so programs that expect to
on the file will not work.
.SS Parameter Substitution.
(a parameter denoted by an identifier)
The attributes supported by the Shell are described
Exported parameters pass values and attributes to
sub-shells but only values to the environment.
The shell supports a limited one-dimensional array facility.
An element of an array parameter is referenced by a
.I arithmetic expression\^
(see Arithmetic evaluation below)
subscripts must be in the
Arrays need not be declared.
Any reference to a named parameter
with a valid subscript is
legal and an array will be created if necessary.
Referencing an array without a subscript
is equivalent to referencing the first element.
may also be assigned by writing:
If the integer attribute,
is subject to arithmetic evaluation as described below.
parameters denoted by a number,
may be assigned values with the
is set from argument zero when the shell
is used to introduce substitutable
\f3${\fP\f2parameter\^\fP\f3}\fP
The value, if any, of the parameter is substituted.
The braces are required when
is followed by a letter, digit, or underscore
that is not to be interpreted as part of its name
or when a named parameter is subscripted.
is one or more digits then it is a positional parameter.
A positional parameter of more than one digit must be
parameters, starting with
(separated by a field separator character).
(separated by a field separator character).
\f3${#\fP\f2parameter\^\fP\f3}\fP
the number of positional parameters is substituted.
Otherwise, the length of the value of the
\f3${#\fP\f2identifier\fP\f3[*]}\fP
The number of elements in the array
\f3${\fP\f2parameter\^\fP\f3:\-\fP\f2word\^\fP\f3}\fP
is set and is non-null then substitute its value;
\f3${\fP\f2parameter\^\fP\f3:=\fP\f2word\^\fP\f3}\fP
is not set or is null then set it to
the value of the parameter is then substituted.
Positional parameters may not be assigned to
\f3${\fP\f2parameter\^\fP\f3:?\fP\f2word\^\fP\f3}\fP
is set and is non-null then substitute its value;
is omitted then a standard message is printed.
\f3${\fP\f2parameter\^\fP\f3:+\fP\f2word\^\fP\f3}\fP
is set and is non-null then substitute
otherwise substitute nothing.
\f3${\fP\f2parameter\^\fP\f3#\fP\f2pattern\^\fP\f3}\fP
\f3${\fP\f2parameter\^\fP\f3##\fP\f2pattern\^\fP\f3}\fP
matches the beginning of the value of
this substitution is the value of the
with the matched portion deleted;
otherwise the value of this
In the first form the smallest matching pattern is deleted and in the
latter form the largest matching pattern is deleted.
\f3${\fP\f2parameter\^\fP\f3%\fP\f2pattern\^\fP\f3}\fP
\f3${\fP\f2parameter\^\fP\f3%%\fP\f2pattern\^\fP\f3}\fP
matches the end of the value of
with the matched part deleted;
otherwise substitute the value of
In the first form the smallest matching pattern is deleted and in the
latter form the largest matching pattern is deleted.
is not evaluated unless it is
to be used as the substituted string,
so that, in the following example,
echo \|${d:\-\^$(\^pwd\^)\^}
is omitted from the above expressions,
then the shell only checks whether
are automatically set by the shell:
The number of positional parameters in decimal.
Flags supplied to the shell on invocation or by
The decimal value returned by the last executed command.
The process number of this shell.
The last argument of the previous command.
This parameter is not set for commands which are asynchronous.
This parameter is also used to hold the name of the matching
file when checking for mail.
Finally, the value of this parameter is set to the full path name of
each program the shell invokes and is passed in the
The process number of the last background command invoked.
The process number of the parent of the shell.
The present working directory set by the
The previous working directory set by the
Each time this parameter is referenced, a random integer is generated.
The sequence of random numbers can be initialized by assigning
This parameter is set by the
special command when no arguments are supplied.
Each time this parameter is referenced, the number of
seconds since shell invocation is returned. If this parameter is
assigned a value, then the value returned upon reference will
be the value that was assigned plus the number of seconds since the assignment.
the value is used to define the width of the edit window
for the shell edit modes and for printing
If the value of this variable ends in
then the corresponding option
If this parameter is set, then
parameter substitution is performed on
the pathname of the script that will be
This file is typically used for
The default editor name for the
Internal field separators,
that is used to separate command words which result from
command or parameter substitution
and for separating words with the special command
The first character of the
parameter is used to separate arguments for the
If this parameter is set when the shell is invoked, then
the value is the pathname of the file that will be
used to store the command history.
If this parameter is set when the shell is invoked, then
the number of previously entered commands that
are accessible by this shell
will be greater than or equal to this number.
The default argument (home directory) for the
the value is used to determine the column length for printing
Select lists will print vertically until about two-thirds of
If this parameter is set to the name of a mail file
then the shell informs the user of arrival of mail
This variable specifies how often (in seconds) the
shell will check for changes in the modification time
of any of the files specified by the
The default value is 600 seconds.
When the time has elapsed
the shell will check before issuing the next prompt.
separated list of file names.
then the shell informs the user of
any modifications to the specified files
that have occurred within the last
Each file name can be followed by a
and a message that will be printed.
The message will undergo parameter and command substitution
defined as the name of the file that has changed.
.I you have mail in $_\^.
The search path for commands (see
The value of this parameter is expanded for parameter
substitution to define the
primary prompt string which by default is
in the primary prompt string is replaced by the
Secondary prompt string, by default
is kept in the environment.
At invocation, if the value of this variable contains an
then the shell becomes restricted.
If set to a value greater than zero,
the shell will terminate if a command is not entered within
the prescribed number of seconds after issuing the
(Note that the shell can be compiled with a maximum bound
for this value which cannot be exceeded.)
If the value of this variable ends in
then the corresponding option
The shell gives default values to
\f3\s-1PATH\s+1\fP, \f3\s-1PS1\s+1\fP, \f3\s-1PS2\s+1\fP, \f3\s-1MAILCHECK\s+1\fP,
\f3\s-1TMOUT\s+1\fP and \f3\s-1IFS\s+1\fP,
not set at all by the shell (although
.SS Blank Interpretation.
After parameter and command substitution,
the results of substitutions are scanned for the field separator
and split into distinct arguments where such characters are found.
Explicit null arguments (\^\f3"\^"\fP or \f3\*\(fm\^\*\(fm\fP\^) are retained.
that have no values) are removed.
.SS File Name Generation.
Following substitution, each command
If one of these characters appears
then the word is regarded as a
The word is replaced with alphabetically sorted file names that match the pattern.
If no file name is found that matches the pattern, then
the word is left unchanged.
is used for file name generation,
at the start of a file name
or immediately following a
must be matched explicitly.
In other instances of pattern matching the
are not treated specially.
Matches any string, including the null string.
Matches any single character.
.BR \*(OK \^.\|.\|.\^ \*(CK
Matches any one of the enclosed characters.
A pair of characters separated by
character lexically between the pair, inclusive.
If the first character following the opening "[ \|"
is a "! \|" then any character not enclosed is matched.
can be included in the character set by putting it as the
has a special meaning to the shell
and causes termination of a word unless quoted.
(i.e., made to stand for itself)
All characters enclosed between a pair of single quote marks (\^\f3\(fm\^\(fm\fP\^),
A single quote cannot appear within single quotes.
Inside double quote marks
parameter and command substitution occurs and
is identical when not quoted or when used as a parameter assignment value
or as a file name. However,
when used as a command argument,
\f3"$1\fP\f2d\fP\f3\|$2\fP\f2d\fP\|.\|.\|.\f3"\fP,
is the first character of the
If the grave quotes occur within double quotes then
also quotes the character
The special meaning of keywords or aliases can be removed by quoting any
character of the keyword.
The recognition of function names or special command names listed below
cannot be altered by quoting them.
.SS Arithmetic Evaluation.
An ability to perform integer arithmetic
is provided with the special command
Evaluations are performed using
Constants are of the form
\*(OK\f2base\f3#\^\f1\*(CK\f2n\^\fP
is a decimal number between two and thirty-six
representing the arithmetic base
is a number in that base.
An internal integer representation of a
can be specified with the
When this attribute is selected
the first assignment to the
parameter determines the arithmetic base
parameter substitution occurs.
Since many of the arithmetic operators require
quoting, an alternative form of the
For any command which begins with a
all the characters until a matching
are treated as a quoted expression.
the shell prompts with the value of
before reading a command.
If at any time a new-line is typed and further input is needed
to complete a command, then the secondary prompt
Before a command is executed, its input and output
may be redirected using a special notation interpreted by the shell.
The following may appear anywhere in a simple-command
or may precede or follow a
passed on to the invoked command.
Command and parameter substitution occurs before
is used except as noted below.
occurs only if the pattern matches a single file
and blank interpretation is not performed.
as standard input (file descriptor 0).
as standard output (file descriptor 1).
If the file does not exist then it is created;
otherwise, it is truncated to zero length.
If the file exists then output is appended to it (by first seeking to the end-of-file);
otherwise, the file is created.
\f3<\h@-.3m@<\fP\*(OK\f3\-\fP\*(CK\f2word\fP
The shell input is read up to a line that is the same as
No parameter substitution, command substitution or
file name generation is performed on
is quoted, then no interpretation
is placed upon the characters of the document;
otherwise, parameter and command substitution occurs,
must be used to quote the characters
and the first character of
then all leading tabs are stripped from
The standard input is duplicated from file descriptor
Similarly for the standard output using
The standard input is closed.
Similarly for the standard output using
If one of the above is preceded by a digit,
file descriptor number referred to is that specified
(instead of the default 0 or 1).
means file descriptor 2 is to be opened
for writing as a duplicate
The order in which redirections are specified is significant.
The shell evaluates each redirection in terms of the
.RI ( "file descriptor" ", " file )
association at the time of evaluation.
\&.\|.\|. \|1>\f2fname\^\fP 2>&1
first associates file descriptor 1 with file
It then associates file descriptor 2 with the file associated with file
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
If a command is followed by
and job control is not active,
then the default standard input
Otherwise, the environment for the execution of a command contains the
file descriptors of the invoking shell as modified by
input/output specifications.
is a list of name-value pairs that is passed to
an executed program in the same way as a normal argument list.
and the values are character strings.
The shell interacts with the environment in several ways.
On invocation, the shell scans the environment
giving it the corresponding value and marking it
Executed commands inherit the environment.
If the user modifies the values of these
commands they become part of the
The environment seen by any executed command is thus composed
of any name-value pairs originally inherited by the shell,
whose values may be modified by the current shell,
may be augmented by prefixing it with one or more parameter assignments.
A parameter assignment argument is a word of the form
\s-1TERM\s+1=450 \|cmd \|args and
(export \|\s-1TERM\s+1; \|\s-1TERM\s+1=450; \|cmd \|args)
are equivalent (as far as the above execution of
parameter assignment arguments are placed in the environment,
even if they occur after the command name.
keyword, described in the
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, traps ( other than
and present working directory with the
is executed after the function completes.
variables are shared between the calling program
special command used within a function
defines local variables whose scope includes
Errors within functions return control to the caller.
The text of functions will also
Function can be undefined with the
functions are unset when the shell executes a shell script.
command allows a function to be exported
to scripts that are executed without a separate
Functions that need to be defined across separate
invocations of the shell should be placed in the
an interactive shell associates a \fIjob\fR with each pipeline. It keeps
a table of current jobs, printed by the
command, and assigns them small integer numbers. When
a job is started asynchronously with
the shell prints a line which looks
indicating that the job which was started asynchronously was job number
1 and had one (top-level) process, whose process id was 1234.
This paragraph and the next require features that are
not in all versions of UNIX and may not apply.
If you are running a job and wish to do something else you may hit the key
\fB^Z\fR (control-Z) which sends a STOP signal to the current job.
The shell will then normally indicate that the job has been `Stopped',
and print another prompt. You can then manipulate the state of this job,
putting it in the background with the
command, or run some other
commands and then eventually bring the job back into the foreground with
A \fB^Z\fR takes effect immediately and
is like an interrupt in that pending output and unread input are discarded
A job being run in the background will stop 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''.
tty option, then background jobs will stop when they try to produce
output like they do when they try to read input.
There are several ways to refer to jobs in the shell. The character
introduces a job name. If you wish to refer to job number 1, you can
Jobs can also be named by prefixes of the string typed in to
Thus, on systems that support job control,
job, if there were a suspended job whose name began with
The shell maintains a notion of the current and previous jobs.
In output pertaining to jobs, the current job is marked with a
and the previous job with a
refers to the previous job.
is also a synonym for the current job.
This shell learns immediately whenever a process changes state.
It normally informs you whenever a job becomes blocked so that
no further progress is possible, but only just before it prints
a prompt. This is done so that it does not otherwise disturb your work.
When you try to leave the shell while jobs are running or stopped, you will
be warned that `You have stopped(running) jobs.' You may use the
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, and the stopped
The \s-1INT\s+1 and \s-1QUIT\s+1 signals for an invoked
command are ignored if the command is followed by
Otherwise, signals have the values
inherited by the shell from its parent
Each time a command is executed, the above substitutions
If the command name matches one
it is executed within the
Next, the command name is checked to see if
it matches one of the user defined functions.
the positional parameters are saved
and then reset to the arguments of the
the positional parameter list is restored
within the function is executed.
is the value of the last command executed.
A function is also executed in the
If a command name is not a
an attempt is made to execute the command via
defines the search path for
the directory containing the command.
Alternative directory names are separated by
and the current directory
The current directory can be specified by
two or more adjacent colons, or by a colon
at the beginning or end of the path list.
If the command name contains a \f3/\fP then the search path
Otherwise, each directory in the path is
searched for an executable file.
If the file has execute permission but is not a
it is assumed to be a file containing shell commands.
A sub-shell is spawned to read it.
All non-exported aliases,
and named parameters are removed in this case.
file doesn't have read permission,
bits are set on the file,
then the shell executes an agent whose job it is to
set up the permissions and execute the shell with the
shell command file passed down as an open file.
A parenthesized command is also executed in
a sub-shell without removing non-exported quantities.
commands entered from a terminal device
.B \s-1$HOME\s+1/.sh_history
A shell can access the commands of
shells which use the same named
edit a portion of this file.
The portion of the file to be edited or listed can be selected by
number or by giving the first character or
characters of the command.
A single command or range of commands can be specified.
If you do not specify an editor program as
then the value of the parameter
The edited command(s) is printed and re-executed upon
is used to skip the editing phase and
to re-execute the command.
In this case a substitution parameter of the form
\f2old\fP\f3=\fP\f2new\fP
can be used to modify the command before execution.
will re-execute the most recent command which starts with the letter
replacing the first occurrence of the string
.SS In-line Editing Options
Normally, each command line entered from a terminal device is simply
typed followed by a new-line (`RETURN' or `LINE\ FEED').
option is active, the user can edit the command line.
To be in either of these edit modes
An editing option is automatically selected each time the
variable is assigned a value ending in either of these
The editing features require that the user's terminal
accept `RETURN' as carriage return without line feed
and that a space (`\ ') must overwrite the current character on
ADM terminal users should set the "space - advance"
Hewlett-Packard series 2621 terminal users should set the straps to
The editing modes implement a concept where the user is looking through a
window at the current line.
The window width is the value of
if it is defined, otherwise 80.
If the line is longer than the window width minus two, a mark is
displayed at the end of the window to notify the user.
As the cursor moves and reaches the window boundaries the window will be
centered about the cursor.
if the line extends on the
right (left, both) side(s) of the window.
This mode is entered by enabling either the
The only difference between these two modes is the way
moves the cursor to the point needing correction and
then inserts or deletes characters or words as needed.
All the editing commands are control characters or escape
The notation for control characters is caret (
is the notation for control
This is entered by depressing `f' while holding down the
indicates the DEL (delete) key.)
The notation for escape sequences is
is entered by depressing ESC
would be the notation for ESC followed by `SHIFT' (capital) `F'.)
operate from any place on the line
(not just at the beginning).
Neither the "RETURN" nor the "LINE FEED" key is
entered after edit commands except when noted.
Move cursor forward (right) one character.
Move cursor forward one word.
(The editor's idea of a word is a string of characters
consisting of only letters, digits and underscores.)
Move cursor backward (left) one character.
Move cursor backward one word.
Move cursor to start of line.
Move cursor to end of line.
Interchange the cursor and mark.
(User defined erase character as defined
by the stty command, usually
Delete previous character.
Delete current character.
(Meta-backspace) Delete previous word.
(Meta-DEL) Delete previous word (if your interrupt character is
(DEL, the default) then this command will not work).
Transpose current character with next character in
Transpose two previous characters in
Capitalize current character.
Change the current word to lower case.
Kill from the cursor to the end of the line.
If given a parameter of zero then kill from
the start of line to the cursor.
Kill from the cursor to the mark.
Push the region from the cursor to the mark on the stack.
(User defined kill character as defined
by the stty command, usually
Kill the entire current line.
characters are entered in succession, all
kill characters from then on cause a line feed
(useful when using paper terminals).
Restore last item removed from line. (Yank item back to the line.)
Line feed and print current line.
(Null character) Set mark.
(New\ line) Execute the current line.
(Return) Execute the current line.
if the current line is null.
the previous command back in time is accessed.
Fetch the least recent (oldest) history line.
Fetch the most recent (youngest) history line.
the next command forward in time is accessed.
Reverse search history for a previous command line containing
If a parameter of zero is given, the search is forward.
is terminated by a "RETURN" or "NEW\ LINE".
then the next command line containing the most recent
In this case a parameter of zero
reverses the direction of the search.
Operate \- Execute the current line and fetch
the next line relative to current line from the
(Escape) Define numeric parameter, the digits
are taken as a parameter to the next command.
The commands that accept a parameter are
Soft-key \- Your alias list is searched for an
and if an alias of this name is defined, its
value will be inserted on the input queue.
must not be one of the above meta-functions.
The last word of the previous command is inserted
If preceded by a numeric parameter, the value
of this parameter determines which word to insert rather than
Attempt file name generation on the current word.
An asterisk is appended if the word doesn't contain any special
List files matching current word pattern
if an asterisk were appended.
Multiply parameter of next command by 4.
Editing characters, the user's erase, kill and
in a command line or in a search string if preceded by a
removes the next character's
editing features (if any).
Display version of the shell.
There are two typing modes.
Initially, when you enter a command you are in the
moves the cursor to the point needing correction and
then inserts or deletes characters or words as needed.
Most control commands accept an optional repeat
When in vi mode on most systems,
canonical processing is initially enabled and the
command will be echoed again if the speed is 1200 baud or greater and it
contains any control characters or less than one second has elapsed
since the prompt was printed.
The ESC character terminates canonical processing for the remainder of the command
and the user can than modify the command line.
This scheme has the advantages of canonical processing with the type-ahead
is also set, the terminal will always have canonical processing
disabled. This mode is implicit for systems that do not support two
alternate end of line delimiters,
and may be helpful for certain terminals.
.SS "\ \ \ \ \ Input Edit Commands"
By default the editor is in input mode.
(User defined erase character as defined
by the stty command, usually
Delete previous character.
Delete the previous blank separated word.
Editing characters, the user's erase or kill
characters may be entered
in a command line or in a search string if preceded by a
removes the next character's
editing features (if any).
.SS "\ \ \ \ \ Motion Edit Commands"
These commands will move the cursor.
Cursor forward (right) one character.
Cursor forward one alpha-numeric word.
Cursor to the beginning of the next word that follows a blank.
Cursor to end of the current blank delimited word.
Cursor backward (left) one character.
Cursor backward one word.
Cursor to preceding blank separated word.
[\f2count\fP]\f3f\fP\f2c\fP
Find the next character \fIc\fP in the current line.
[\f2count\fP]\f3F\fP\f2c\fP
Find the previous character \fIc\fP in the current line.
[\f2count\fP]\f3t\fP\f2c\fP
[\f2count\fP]\f3T\fP\f2c\fP
Repeats the last single character find command,
Reverses the last single character find command.
Cursor to first non-blank character in line.
.SS "\ \ \ \ \ Search Edit Commands"
These commands access your command history.
the previous command back in time is accessed.
the next command forward in time is accessed.
The default is the least recent history command.
Search backward through history for a previous command containing
is terminated by a "RETURN" or "NEW\ LINE".
If \fIstring\fP is null the previous string will be used.
except that search will be in the forward direction.
Search for next match of the last pattern to
Search for next match of the last pattern to
but in reverse direction.
Search history for the \fIstring\fP entered by the previous \fB/\fP command.
.SS "\ \ \ \ \ Text Modification Edit Commands"
These commands will modify the line.
Enter input mode and enter text after the current character.
Append text to the end of the line. Equivalent to
[\f2count\fP]\f3c\fP\f2motion\fP
\f3c\fP[\f2count\fP]\f2motion\fP
Delete current character through the character that
would move the cursor to and enter input mode.
the entire line will be deleted and
Delete the current character through the end of line and enter input mode.
Delete the current character through the end of line.
[\f2count\fP]\f3d\fP\f2motion\fP
\f3d\fP[\f2count\fP]\f2motion\fP
Delete current character through the character that
the entire line will be deleted.
Enter input mode and insert text before the current character.
Insert text before the beginning of the line. Equivalent to
the two character sequence
Place the previous text modification before the cursor.
Place the previous text modification after the cursor.
replace characters on the screen with characters you type overlay fashion.
Replace the current character with
Delete current character.
Delete preceding character.
Repeat the previous text modification command.
Invert the case of the current character and advance the cursor.
word of the previous command to be appended and
to be appended to the current word and file name generation attempted.
it rings the bell. Otherwise, the word is replaced
by the matching pattern and input mode is entered.
.SS "\ \ \ \ \ Other Edit Commands"
[\f2count\fP]\f3y\fP\f2motion\fP
\f3y\fP[\f2count\fP]\f2motion\fP
Yank current character through character that
would move the cursor to and puts them into the
delete buffer. The text and cursor are unchanged.
Yanks from current position to end of line.
Undo the last text modifying command.
Undo all the text modifying commands performed on the line.
.BI "fc \-e ${\s-1VISUAL\s+1:\-${\s-1EDITOR\s+1:\-vi}}" " count"
is omitted, then the current line is used.
Line feed and print current line.
Has effect only in control mode.
(New\ line) Execute the current line, regardless of mode.
(Return) Execute the current line, regardless of mode.
in front of the line and after each new-line.
Useful for causing the current line to be
inserted in the history without being executed.
List the filenames that match the current word if an asterisk were
Your alias list is searched for an
and if an alias of this name is defined, its
value will be inserted on the input queue for processing.
The following simple-commands are executed in the shell process.
Input/Output redirection is permitted.
Unless otherwise indicated, the output is written on file descriptor 1.
Commands that are preceded by one or two \(dg
are treated specially in the following ways:
Parameter assignment lists preceding the command
remain in effect when the command completes.
They are executed in a separate
process when used within command substitution.
commands preceded by \(dg\(dg
that contains them to abort.
\(dg \f3:\fP \*(OK \f2arg\^\fP .\|.\|. \*(CK
The command only expands parameters.
A zero exit code is returned.
\(dg\(dg \f3\|. \f2file\^\fP \*(OK \f2arg\^\fP .\|.\|. \*(CK
Read and execute commands from
The commands are executed in the current Shell environment.
is used to find the directory containing
they become the positional parameters.
Otherwise the positional parameters are unchanged.
\f3alias\fP \*(OK \f3\-tx\fP \*(CK \*(OK \f2name\fP\*(OK \f2=value\^\fP \*(CK .\|.\|. \*(CK
with no arguments prints the list of aliases
causes the next word to be checked for
flag is used to set and list tracked aliases.
The value of a tracked alias is the full pathname
corresponding to the given
The value becomes undefined when the value of
is reset but the aliases remained tracked.
and value of the alias is printed.
flag is used to set or print exported aliases.
An exported alias is defined across sub-shell environments.
Alias returns true unless a
is given for which no alias has been defined.
\f3bg\fP \*(OK \f3%\fP\f2job\^\fP \*(CK
This command is only built-in on systems that support job control.
The current job is put in the background
\f3break\fP \*(OK \f2n\^\fP \*(CK
\f3continue\fP \*(OK \f2n\^\fP \*(CK
Resume the next iteration of the enclosing
is specified then resume at the
\(dg \f3cd\fP \*(OK \f2arg\^\fP \*(CK
\(dg \f3cd\fP \f2old\^\fP \f2new\^\fP
This command can be in either of two forms.
changes the current directory to
the directory is changed to the previous
is set to the current directory.
defines the search path for
Alternative directory names are separated by
(specifying the current directory).
Note that the current directory is specified by a null path name,
which can appear immediately after the equal sign
or between the colon delimiters anywhere else in the path list.
begins with a \f3/\fP then the search path
Otherwise, each directory in the path is
in the current directory name,
and tries to change to this new directory.
command may not be executed by
\f3echo\fP \*(OK \f2arg\^\fP .\|.\|. \*(CK
for usage and description.
\(dg\(dg \f3eval\fP \*(OK \f2arg\^\fP .\|.\|. \*(CK
The arguments are read as input
and the resulting command(s) executed.
\(dg\(dg \f3exec\fP \*(OK \f2arg\^\fP .\|.\|. \*(CK
the arguments is executed in place of this shell
without creating a new process.
Input/output arguments may appear and
affect the current process.
the effect of this command is to
as prescribed by the input/output redirection list.
any file descriptor numbers greater than 2 that are
opened with this mechanism are closed when invoking
\f3exit\fP \*(OK \f2n\^\fP \*(CK
with the exit status specified by
is omitted then the exit status is that of the last command executed.
An end-of-file will also cause the shell to exit
\(dg\(dg \f3export\fP \*(OK \f2name\^\fP .\|.\|. \*(CK
of subsequently-executed commands.
\(dg\(dg \f3fc\fP \*(OK \f3\-e\fP \f2ename\^\fP \ \*(CK \*(OK \f3\-nlr\^\fP \*(CK \*(OK \f2first\^\fP \*(CK \*(OK \f2last\^\fP \*(CK
\(dg\(dg \f3fc \-e \-\fP \*(OK \f2old\fP\f3\=\fP\f2new\^\fP \*(CK \*(OK \f2command\^\fP \*(CK
is selected from the last
commands that were typed at the terminal.
may be specified as a number or as a string.
A string is used to locate the most recent command starting with
A negative number is used as an offset to the current command number.
the commands are listed on standard output.
Otherwise, the editor program
is invoked on a file containing these
is not supplied, then the value of the parameter
When editing is complete, the edited command(s)
the default is the previous command
for editing and \-16 for listing.
reverses the order of the commands and
suppresses command numbers when listing.
is re-executed after the substitution
\f2old\^\fP\f3=\fP\f2new\^\fP
\f3fg\fP \*(OK \f3%\fP\f2job\^\fP \*(CK
This command is only built-in on systems that support job control.
is specified it brings it to the foreground.
Otherwise, the current job is
brought into the foreground.
\f3jobs\fP \*(OK \f3\-l\^\fP \*(CK
Lists the active jobs; given the
options lists process id's in addition to the normal information.
\f3kill\fP \*(OK \f3\-\fP\f2sig\^\fP \*(CK \f2process\^\fP .\|.\|.
Sends either the TERM (terminate) signal or the
specified signal to the specified jobs or processes.
Signals are either given by number or by names (as given in
.BR /usr/include/signal.h ,
stripped of the prefix ``SIG'').
The signal numbers and names are listed by
If the signal being sent is TERM (terminate) or HUP (hangup),
then the job or process will be sent a CONT (continue) signal
can be either a process id or a job.
\f3let\fP \f2arg\^\fP .\|.\|.
.IR "arithmetic expression"
All calculations are done as long
integers and no check for overflow
Expressions consist of constants,
named parameters, and operators.
The following set of operators,
listed in order of decreasing precedence,
multiplication, division, remainder
Sub-expressions in parentheses
are evaluated first and can be used
to override the above precedence rules.
The evaluation within a precedence group
is from right to left for the
and from left to right for the others.
A parameter name must be a valid
When a parameter is encountered,
the value associated with the
parameter name is substituted and expression evaluation resumes.
Up to nine levels of recursion are
0 if the value of the last expression
is non-zero, and 1 otherwise.
\(dg\(dg \f3newgrp\fP \*(OK \f2arg\^\fP .\|.\|. \*(CK
.BI "exec newgrp" " arg\^"
\f3print\fP \*(OK \f3\-Rnprsu\^\fP\*(OK\f2n\fP \*(CK \*(CK \*(OK \f2arg\^\fP .\|.\|. \*(CK
The shell output mechanism.
With no flags or with flag
the arguments are printed
on standard output as described by
the escape conventions of
option will print all subsequent arguments and options
arguments to be written onto the pipe
of the process spawned with
instead of standard output.
arguments to be written onto the history file
instead of standard output.
flag can be used to specify a one digit
file descriptor unit number
\f3print \-r \- $\s-1PWD\s+1\fP
\f3read\fP \*(OK \f3\-prsu\^\fP\*(OK \f2n\^\fP \*(CK \*(CK \*(OK \f2name\f3?\f2prompt\^\f1 \*(CK \*(OK \f2name\^\fP .\|.\|. \*(CK
The shell input mechanism.
is broken up into words using the characters in
at the end of a line does not signify
word is assigned to the first
etc., with leftover words assigned to the last
option causes the input line
to be taken from the input pipe
of a process spawned by the shell
the input will be saved as a command in the history file.
can be used to specify a one digit file
descriptor unit to read from.
The file descriptor can be opened with the
The return code is 0 unless an end-of-file is encountered.
option causes cleanup for this process
so that another can be spawned.
If the first argument contains a
the remainder of this word is used as a
when the shell is interactive.
If the given file descriptor is open for writing
and is a terminal device then the prompt is placed
Otherwise the prompt is issued on file descriptor 2.
The return code is 0 unless an end-of-file is encountered.
\(dg\(dg \f3readonly\fP \*(OK \f2name\fP .\|.\|. \*(CK
by subsequent assignment.
\(dg\(dg \f3return\fP \*(OK \f2n\^\fP \*(CK
with the return status specified by
is omitted then the return status is that of the last command executed.
is invoked while not in a
then it is the same as an
\f3set\fP \*(OK \f3\-aefhkmnostuvx\fP \*(CK \*(OK \f3\-o\fP \f2option\^\fP .\|.\|. \*(CK \*(OK \f2arg\^\fP .\|.\|. \*(CK
The flags for this command have meaning as follows:
All subsequent parameters that are defined are automatically exported.
If the shell is non-interactive and if a command fails,
This mode is disabled while reading profiles.
Disables file name generation.
Each command whose name is an
becomes a tracked alias when first encountered.
All parameter assignment arguments are placed in the environment for a command,
not just those that precede the command name.
Background jobs will run in a separate process group
and a line will print upon completion.
The exit status of background jobs is reported in a completion message.
On systems with job control,
this flag is turned on automatically for
Read commands but do not execute them.
Ignored for interactive shells.
The following argument can be one of the following option names:
All background jobs are run at a lower priority.
style in-line editor for command entry.
style in-line editor for command entry.
The shell will not exit on end-of-file.
All directory names resulting from file name generation have a trailing
Puts you in insert mode of a
until you hit escape character
This puts you in move mode.
Each character is processed as it is typed
If no option name is supplied then the current option settings are printed.
variable to the default value, disables processing of the
.B \s-1$HOME\s+1/.profile
This mode is automatically enabled whenever the effective uid (gid)
is not equal to the real uid (gid).
Sort the positional parameters.
Exit after reading and executing one command.
Treat unset parameters as an error when substituting.
Print shell input lines as they are read.
Print commands and their arguments as they are executed.
flags and stops examining arguments for flags.
Do not change any of the flags; useful in setting
to a value beginning with
If no arguments follow this flag then the positional parameters are unset.
causes these flags to be turned off.
These flags can also be used upon invocation of the shell.
The current set of flags may be found in
The remaining arguments are positional
parameters and are assigned, in order,
If no arguments are given then the values
of all names are printed on the standard output.
\(dg \f3shift\fP \*(OK \f2n\^\fP \*(CK
The positional parameters from
can be any arithmetic expression that evaluates to a non-negative
number less than or equal to
\f3test\fP \*(OK \f2expr\^\fP \*(CK
Evaluate conditional expression
for usage and description.
The arithmetic comparison operators
are not restricted to integers.
They allow any arithmetic expression.
Four additional primitive expressions are allowed:
\f2file1\^\fP \f3\-nt\fP \f2file2\^\fP
\f2file1\^\fP \f3\-ot\fP \f2file2\^\fP
\f2file1\^\fP \f3\-ef\fP \f2file2\^\fP
has the same device and i-node number as
Print the accumulated user and system times for
the shell and for processes
\f3trap\fP \*(OK \f2arg\^\fP \*(CK \*(OK \f2sig\^\fP \*(CK .\|.\|.
is a command to be read and executed when the shell
the trap is set and once when the trap
can be given as a number or as the name of the signal.
Trap commands are executed in order of signal number.
Any attempt to set a trap on a signal that
was ignored on entry to the current shell
to their original values.
string then this signal is ignored by the shell and by the commands
will be executed whenever a command has a non-zero exit code.
This trap is not inherited by functions.
statement is executed inside the body of a function,
after the function completes.
with no arguments prints a list
of commands associated with each signal number.
\(dg\(dg \f3typeset\fP \*(OK \f3\-HLRZfilprtux\^\fP\*(OK\f2n\fP \*(CK \*(OK \f2name\fP\*(OK \f2=value\^\fP \*(CK \^ \*(CK .\|.\|. \*(CK
When invoked inside a function,
a new instance of the parameter
The parameter value and type are restored
when the function completes.
The following list of attributes may be specified:
This flag provides UNIX to host-name file mapping on non-UNIX
Left justify and remove leading blanks from
is non-zero it defines the width
otherwise it is determined by the width of the value of
When the parameter is assigned to, it is
filled on the right with blanks or truncated, if necessary, to
Leading zeros are removed if the
Right justify and fill with leading blanks.
is non-zero it defines the width
otherwise it is determined by the width of the value of
The field is left filled with blanks or
truncated from the end if the
Right justify and fill with leading zeros if
the first non-blank character is a digit and the
is non-zero it defines the width
otherwise it is determined by the width of the value of
The names refer to function names rather than
No assignments can be made and the only other
which turns on execution tracing for this function and
to allow the function to remain in effect across shell
procedures executed in the same process environment.
This makes arithmetic faster.
is non-zero it defines the output arithmetic base,
otherwise the first assignment determines the output base.
All upper-case characters
The output of this command, if any, is written onto the two-way pipe
by subsequent assignment.
Tags the named parameters.
Tags are user definable and have no special
All lower-case characters are converted
to upper-case characters.
of subsequently-executed commands.
causes these flags to be turned off.
arguments are given but flags are specified,
\f3ulimit\fP \*(OK \f3\-acdfmpst\fP \*(CK \*(OK \f2n\^\fP \*(CK
Lists all of the current resource limits
512 byte blocks on the size of core dumps
kbytes on the size of the data area
512 byte blocks on files written by child processes (files of any size may be read).
kbytes on the size of physical memory
(\s-1UNIX\s+1/\s-1RT\s+1 only).
kbytes on the size of the stack area
seconds to be used by each process
is not given the current limit is printed.
\f3umask\fP \*(OK \f2nnn\^\fP \*(CK
The user file-creation mask is set to
is omitted, the current value of the mask is printed.
\f3unalias\fP \f2name\^\fP .\|.\|.
\f3unset\fP \*(OK \f3\-f\fP \*(CK \f2name\^\fP .\|.\|.
The parameters given by the list of
their values and attributes are erased.
Readonly variables cannot be unset.
is set, then the names refer to
\f3wait\fP \*(OK \f2n\^\fP \*(CK
Wait for the specified child process and
report its termination status.
is not given then all currently active child processes are waited for.
The return code from this command is that of
\f3whence\fP \*(OK \f3\-v\fP \*(CK \f2name\^\fP .\|.\|.
would be interpreted if used as a command name.
produces a more verbose report.
If the shell is invoked by
and the first character of argument zero
then the shell is assumed to be a
in the current directory or
.BR \s-1$HOME\s+1/.profile ,
Next, commands are read from
performing parameter substitution on
the value of the environment parameter
is, then a path search is performed on the first
to determine the name of the script to execute.
must have read permission and any
settings will be ignored.
Commands are then read as described below;
the following flags are interpreted by the shell
then commands are read from the standard input.
except for the output of the
if the shell input and output are attached to a terminal (as told by
In this case \s-1TERM\s+1 is ignored (so that \f3kill 0\fP
does not kill an interactive shell) and \s-1INTR\s+1 is caught and ignored
In all cases, \s-1QUIT\s+1 is ignored by the shell.
flag is present the shell is a restricted shell.
The remaining flags and arguments are described under the
is used to set up login names and execution environments whose
capabilities are more controlled than those of the standard shell.
are identical to those of
except that the following are disallowed:
The restrictions above are enforced
after \f3.profile\fP and the
When a command to be executed is found to be a shell procedure,
Thus, it is possible to provide to the end-user shell procedures
that have access to the full power of
while imposing a limited menu of commands;
this scheme assumes that the end-user does not have write and
execute permissions in the same directory.
The net effect of these rules is that the writer of the
has complete control over user actions,
by performing guaranteed setup actions
and leaving the user in an appropriate directory
The system administrator often sets up a directory
that can be safely invoked by
Some systems also provide a restricted editor
Errors detected by the shell, such as syntax errors,
to return a non-zero exit status.
Otherwise, the shell returns the exit status of
the last command executed (see also the
If the shell is being used non-interactively
then execution of the shell file is abandoned.
Runtime errors detected by the shell are reported by
printing the command or function name and the error condition.
If the line number that the error occurred on is greater than one,
then the line number is also printed in square brackets
after the command or function name.
\s-1$HOME\s+1/\f3.\fPprofile
is executed, and then a command with the same name is
installed in a directory in the search path before the directory where the
original command was found, the shell will continue to
command to correct this situation.
Some very old shell scripts contain a
as a synonym for the pipe character.
If a command is piped into a shell command, then all variables set in
the shell command are lost when the command completes.
built-in command within a compound command will cause the whole
command to disappear from the history file.
The built-in command \f3\|.\fP \f2file\^\fP
reads the whole file before any commands are executed.
will not apply to any functions defined in the file.