sh-posix(1)sh-posix(1)NAME
sh-posix: sh, rsh - standard and restricted POSIX.2-conformant command
shells
SYNOPSIS
option]... string] [arg]...
option]... string] [arg]...
Remarks
This shell is intended to conform to the shell specification of the
POSIX.2 standards. Check any standards conformance documents shipped
with your system for information on the conformance of this shell to
any other standards.
List of Subheadings in DESCRIPTION
Shell Invocation Tilde Substitution Environment
Options Command Substitution Functions
rsh Restrictions Parameter Substitution Jobs
Definitions Blank Interpretation Signals
Commands File Name Generation Execution
Simple Commands Quoting Command Reentry
Compound Commands Arithmetic Evaluation Command Line Editing
Special Commands Prompting emacs/gmacs Editing Mode
Comments Conditional Expressions vi Editing Mode
Aliasing Input/Output
DESCRIPTION
is a command programming language that executes commands read from a
terminal or a file.
is a restricted version of See the subsection below.
Shell Invocation
If the shell is invoked by an system call and the first character of
argument zero (shell parameter is dash the shell is assumed to be a
login shell and commands are read first from then from either in the
current directory or if either file exists, and finally from the file
named by performing parameter substitution on the value of the environ‐
ment parameter if the file exists. If the option is not present and an
arg is, a path search is performed on the first arg to determine the
name of the script to execute. When running with arg, the script arg
must have read permission and any and settings will be ignored. Com‐
mands are read as described below.
Shell output, except for the output of some of the commands listed in
the subsection, is written to standard error (file descriptor 2).
Options
The following options are interpreted by the shell when it is invoked.
Read commands from
string.
If is present or if the shell input and output are attached to
a terminal (as reported by the shell is interactive. In
this case is ignored and is caught and ignored (so that is
interruptible). In all cases, is ignored by the shell. See
signal(5).
The shell is a restricted shell.
If is present or if no arguments remain, commands are read from
the standard input.
The remaining options and operands are described under the command in
the subsection.
rsh Restrictions
is used to set up login names and execution environments where capabil‐
ities are more controlled than those of the standard shell. The
actions of are identical to those of except that the following are for‐
bidden:
· Changing directory (see the special command and cd(1))
· Setting the value of or
· Specifying path or command names containing
· Redirecting output and
The restrictions above are enforced after the and files are inter‐
preted.
When a command to be executed is found to be a shell procedure, invokes
to execute it. Thus, the end-user is provided with shell procedures
accessible to the full power of the standard shell, while being
restricted to a limited menu of commands. This scheme assumes that the
end-user does not have write and execute permissions in the same direc‐
tory.
These rules effectively give the writer of the file complete control
over user actions, by performing guaranteed set-up actions and leaving
the user in an appropriate directory (probably not the login direc‐
tory).
The system administrator often sets up a directory of commands (usually
that can be safely invoked by HP-UX systems provide a restricted editor
(see ed(1)), suitable for restricted users.
Definitions
One of the following characters:
A tab or a space.
A sequence of letters, digits, or underscores
starting with a letter or underscore. Identifiers
are used as names for and
A sequence of separated by one or more nonquoted
A sequence of characters in the syntax of the shell language.
The shell reads each command and carries out the
desired action, either directly or by invoking sep‐
arate utilities.
A command that is carried out by the shell
without creating a separate process. Except for
documented side effects, most special commands can
be implemented as separate utilities.
Comment delimiter. A word beginning with and all following characters
up to a newline are ignored.
An a decimal number, or one of the characters and See
the subsection.
A that can be assigned a value. See the subsection.
A
A that is known outside the local shell, usually by
means of the special command.
Commands
A command can be a simple command that executes an executable file, a
special command that executes within the shell, or a compound command
that provides flow of control for groups of simple, special, and com‐
pound commands.
Simple Commands
A simple command is a sequence of blank-separated words that may be
preceded by a parameter assignment list. (See the subsection). The
first word specifies the name of the command to be executed. Except as
specified below, the remaining words are passed as arguments to the
invoked command. The command name is passed as argument (see exec(2)).
The value of a simple command is its exit status if it terminates nor‐
mally, or if it terminates abnormally (see signal(5) for a list of
errorstatus values).
A is a sequence of one or more commands separated by a bar and option‐
ally preceded by an exclamation mark The standard output of each com‐
mand but the last is connected by a pipe (see pipe(2)) 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. If does not precede
the pipeline, the exit status of the pipeline is the exit status of the
last command in the pipeline. Otherwise, the exit status of the pipe‐
line is the logical negation of the exit status of the last command in
the pipeline.
A list is a sequence of one or more pipelines separated by or and
optionally terminated by or
Causes sequential execution of the preceding pipeline.
An arbitrary number of newlines can appear in a list,
instead of semicolons, to delimit commands.
Causes asynchronous execution of the preceding pipeline
(that is, the shell does not wait for that pipeline to
finish).
Causes asynchronous execution of the preceding command or pipe‐
line
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 using the
option of the special commands and
Causes the
list following it to be executed only if the preceding
pipeline returns a zero value.
Causes the
list following it to be executed only if the preceding
pipeline returns a nonzero value.
Of these five symbols, and have equal precedence, which is lower than
that of and The symbols and also have equal precedence.
Compound Commands
Unless otherwise stated, the value returned by a compound command is
that of the last simple command executed in the compound command. The
segment separator can be replaced by one or more newlines.
The following keywords are recognized only as the first word of a com‐
mand and when not quoted:
A compound command is one of the following.
Execute the list associated with the first pattern that matches
word. The form of the patterns is identical to that used for
file name generation (see the subsection). The case terminator
cannot be replaced by newlines.
Set identifier to each word in sequence and execute the list.
If word ... is omitted, set identifier to each set positional
parameter instead. See the subsection. Execution ends when
there are no more positional parameters or words in the list.
Define a function named by identifier. A function is called by
executing its identifier as a command. The body of the function
is the list of commands between and See the subsection.
Execute the list and, if its exit status is zero, execute the
first list. Otherwise, execute the list (if any) and, if its
exit status is zero, execute the next list. Failing that, exe‐
cute the list (if any). If no list or list is executed, returns
a zero exit status.
Print the set of words on standard error (file descriptor 2),
each preceded by a number. If word ... is omitted, print the
positional parameters instead (see the subsection). Print the
prompt and read a line from standard input into the parameter If
this line consists of the number of one of the listed words, set
identifier to the corresponding word, execute list, and repeat
the prompt. If the line is empty, print the selection list
again, and repeat the prompt. Otherwise, set identifier to
null, execute list, and repeat the prompt. The select loop
repeats until a special command or end-of-file is encountered.
Execute the pipeline and print the elapsed time, the user time,
and the system time on standard error. Note that the keyword
can appear anywhere in the pipeline to time the entire pipeline.
To time a particular command in a pipeline, see time(1).
Execute the list. If the exit status of the last command in the
list is nonzero, execute the list and execute the list again.
When the exit status of the last command in the list is zero,
terminate the loop. If no commands in the list are executed,
returns a zero exit status.
Execute the list. If the exit status of the last command in the
list is zero, execute the list and execute the list again. When
the exit status of the last command in the list is nonzero, ter‐
minate the loop. If no commands in the list are executed,
returns a nonzero exit status.
Execute list in a separate environment. If two adjacent open
parentheses are needed for nesting, a space must be inserted
between them to avoid arithmetic evaluation.
Execute list, but not in a separate environment. Note that is a
keyword and requires a trailing blank to be recognized.
Evaluate expression and return a zero exit status when expres‐
sion is true. See the subsection for a description of expres‐
sion. Note that and are keywords and require blanks between
them and expression.
Special Commands
Special commands are simple commands that are executed in the shell
process. They permit input/output redirection. Unless otherwise indi‐
cated, file descriptor 1 (standard output) is the default output loca‐
tion and the exit status, when there are no syntax errors, is zero.
Commands that are marked with "%" are treated specially in the follow‐
ing ways:
1. Variable assignment lists preceding the command remain in
effect when the command completes.
2. I/O redirections are processed after variable assignments.
3. Certain errors cause a script that contains them to abort.
Words following commands marked with "&" that are in the format of a
variable assignment are expanded with the same rules as a variable
assignment. This means that tilde substitution is performed after the
sign and word-splitting and file-name generation are not performed.
%
(colon) Only expand parameters. A zero exit status is
returned.
%
(period) Read and execute commands from file and return. The
commands are executed in the current shell environment. The
search path specified by is used to find the directory contain‐
ing file. If any arguments arg are given, they become the posi‐
tional parameters. Otherwise, the positional parameters are
unchanged. The exit status is the exit status of the last com‐
mand executed.
&
With specified, define name as an alias and assign it the value
value. A trailing space in value causes the next word to be
checked for alias substitution.
With omitted, print the list of aliases in the form on standard
output.
With name specified without print the specified alias.
With set tracked aliases. The value of a tracked alias is the
full path name corresponding to the given name. The value of a
tracked alias becomes undefined when the value of is reset, but
the alias remains tracked. With omitted, print the list of
tracked aliases in the form on standard output.
With set exported aliases. An exported alias is defined across
subshell environments. With omitted, print the list of exported
aliases in the form on standard output.
Alias returns true unless a name is given for which no alias has
been defined.
See also the special command.
Put the specified jobs into the background. The current job is
put in the background if job is unspecified. See the subsection
for a description of the format of job. See also the special
command.
%
Exit from the enclosing or loop, if any. If n is specified,
exit from n levels.
In the first form, change the current working directory to arg.
If arg is the directory is changed to the previous directory The
shell parameter is the default arg. After the the and environ‐
ment variables are set to the new current directory and the for‐
mer directory respectively.
With (default), preserve logical naming when treating symbolic
links. moves the current directory one path component closer to
the root directory.
With preserve the physical path when treating symbolic links.
changes the working directory to the actual parent directory of
the current directory.
The shell parameter defines the search path for the directory
containing arg. Alternative directory names are separated by a
colon If is null or undefined, the default value is 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. If arg begins with a the search path is not used. Other‐
wise, each directory in the path is searched for arg. See also
cd(1).
The second form of substitutes the string new for the string old
in the current directory name, and tries to change to this new
directory.
Treat arg as a command, but disable function lookup on arg. See
command(1) for usage and description.
%
Resume the next iteration of the enclosing or loop. If n is
specified, resume at the nth enclosing loop.
Print arg on standard output. See echo(1) for usage and
description. See also the special command.
%
Read the arguments as input to the shell and execute the result‐
ing commands. Allows parameter substitution for keywords and
characters that would otherwise be unrecognized in the resulting
commands.
%
Parameter assignments remain in effect after the command com‐
pletes. If arg is given, execute the command specified by the
arguments in place of this shell without creating a new process.
Input/output arguments may appear and affect the current
process. If no arguments are given, modify file descriptors as
prescribed by the input/output redirection list. In this case,
any file descriptor numbers greater than 2 that are opened with
this mechanism are closed when another program is invoked.
%
Exit from the shell with the exit status specified by n. If n
is omitted, the exit status is that of the last command exe‐
cuted. An end-of-file also causes the shell to exit, except
when a shell has the option set. (See the special command.)
Mark the given variable names for automatic export to the envi‐
ronment of subsequently executed commands. Optionally, assign
values to the variables.
With no arguments, write the names and values of all exported
variables to standard output,
With write the names and values of all exported variables to
standard output, in a format with the proper use of quoting, so
that it is suitable for re-input to the shell as commands that
achieve the same exporting results.
List, or edit and reexecute, commands previously entered to an
interactive shell. A range of commands from first to last is
selected from the last commands typed at the terminal. The
arguments first and last can be specified as a number or string.
A given string is used to locate the most recent command. A
negative number is used to offset the current command number.
With list the commands on standard output. Without invoke the
editor program ename on a file containing these keyboard com‐
mands. If ename is not supplied, the value of the parameter
(default is used as the editor. Once editing has ended, the
commands (if any) are executed. If last is omitted, only the
command specified by first is used. If first is not specified,
the default is the previous command for editing and −16 for
listing.
With reverse the order of the commands.
With suppress command numbers when listing.
With reexecute the command without invoking an editor.
The argument replaces the first occurrence of string in the com‐
mand to be reexecuted by the string new.
Bring each job into the foreground in the order specified. If
no job is specified, bring the current job into the foreground.
See the subsection for a description of the format of job. See
also the special command.
Parse the argument list, or the positional parameters if no
arguments, for valid options. On each execution, return the
next option in name. See getopts(1) for usage and description.
An option begins with a or a An argument not beginning with or
or the argument ends the options. optstring contains the let‐
ters that recognizes. If a letter is followed by a that option
is expected to have an argument. The options can be separated
from the argument by blanks.
For an option specified as name is set to letter. For an option
specified as name is set to The index of the next arg is stored
in The option argument, if any, is stored in If no option argu‐
ment is found, or the option found does not take an argument, is
unset.
A leading in optstring causes to store the letter of an invalid
option in and to set name to for an unknown option and to when a
required option argument is missing. Otherwise, prints an error
message. The exit status is nonzero when there are no more
options.
Affect the way the current shell environment remembers the loca‐
tions of utilities. With utility, add utility locations to a
list of remembered locations. With no arguments, print the con‐
tents of the list. With forget all previously remembered util‐
ity locations.
List information about each given job, or all active jobs if job
is not specified. With list process IDs in addition to the nor‐
mal information. With display only jobs that have stopped or
exited since last notified. With list only the process group.
See the subsection for a description of the format of job.
Send either signal 15 (terminate) or the specified signal to the
specified jobs or processes. If the signal being sent is (ter‐
minate) or (hangup), the job or process is sent a (continue)
signal when stopped. See kill(1) for usage and description.
With list the signal names and numbers.
Evaluate each arg as a separate arithmetic expression. See the
subsection for a description of arithmetic expression evalua‐
tion. The exit status is 0 if the value of the last expression
is nonzero, and 1 otherwise.
%
Replace the current shell with a new one having group as the
user's group. The default group is the user's login group.
With also execute the user's and files. See newgrp(1) for usage
and description. Equivalent to
The shell output mechanism. With no options or with option or
print the arguments on standard output as described in echo(1).
See also printf(1).
With do not add a newline character to the output.
With write the arguments onto the pipe of the process spawned
with instead of standard output.
With or (raw mode), ignore the escape conventions of With print
all subsequent arguments and options other than
With write the arguments into the history file instead of to
standard output.
With specify a one-digit file descriptor unit number n on which
the output will be placed. The default is (standard output).
Print the name of the current working directory (equivalent to
With (the default), preserve the logical meaning of the current
directory. With preserve the physical meaning of the current
directory if it is a symbolic link. See also the special com‐
mand, cd(1), ln(1), and pwd(1).
The shell input mechanism. Read one line (by default, from
standard input) and break it up into words using the characters
in as separators. The first word is assigned to the first name,
the second word to the second name, and so on; the remaining
words are assigned to the last name. See also read(1). The
return code is unless an end-of-file is encountered.
With take the input line from the input pipe of a process
spawned by the shell using An end-of-file with causes cleanup
for this process so that another process can be spawned.
With (raw mode), a at the end of a line does not signify line
continuation.
With save the input as a command in the history file.
With specify a one-digit file descriptor unit to read from. The
file descriptor can be opened with the special command. The
default value of n is (standard input). If name is omitted, is
used as the default name.
If the first argument contains a the remainder of the argument
is used as a prompt when the shell is interactive.
If the given file descriptor is open for writing and is a termi‐
nal device, the prompt is placed on that unit. Otherwise, the
prompt is issued on file descriptor 2 (standard error).
Mark the given names read only. These names cannot be changed
by subsequent assignment.
With write the names and values of all read-only variables to
standard output in a format with the proper use of quoting so
that it is suitable for re-input to the shell as commands that
achieve the same attribute-setting results.
%
Cause a shell function to return to the invoking script with the
return status specified by n. If n is omitted, the return sta‐
tus is that of the last command executed. Only the low 8 bits
of n (decimal 0 to 255) are passed back to the caller. If is
invoked while not in a function or a script (see the special
command), it has the same effect as an command.
% option]...
name] [arg]...
Set or clear execution options or perform array assignments All
options except and can be supplied in a shell invocation (see
the section and the subsection).
Using instead of before an option causes the option to be turned
off. These options can also be used when invoking the shell.
The current list of set single-letter options is contained in
the shell variable It can be examined with the command
The and options can be intermixed in the same command, except
that there can be only one or option.
Unless or is specified, the remaining arg arguments are assigned
consecutively to the positional parameters
The command with neither arguments nor options displays the
names and values of all shell parameters on standard output.
See also env(1).
The options are defined as follows.
Array assignment.
Unset the variable name and assign values sequentially
from the list arg. With do not unset the variable name
first.
Automatically export subsequently defined parameters.
Cause the shell to notify the user asynchronously
of background jobs as they are completed. When the shell
notifies the user that a job has been completed, it can
remove the job's process ID from the list of those known
in the current shell execution environment.
Prevent redirection
from truncating existing regular files. Requires to
truncate a file when turned on.
Execute the
trap, if set, and exit if a command has a nonzero exit
status, and is not part of the compound list following a
or keyword, and is not part of an AND or OR list, and is
not a pipeline preceded by the reserved word. This mode
is disabled while reading profiles.
Disable file name generation.
Specify that each command whose name is an
identifier becomes a tracked alias when first encoun‐
tered.
Place all parameter assignment arguments
(not just those that precede the command name) into the
environment for a command.
Run background jobs in a separate process group
and print a line upon completion. The exit status of
background jobs is reported in a completion message.
This option is turned on automatically for interactive
shells.
Read commands and check them for syntax errors, but do not exe‐
cute them.
The option is ignored for interactive shells.
Set an option argument from the following list. Repeat the
option to specify additional option arguments.
Same as
Run all background jobs at a lower priority.
Use a inline editor for command entry.
Same as
Use a inline editor for command entry.
Do not exit from the shell on end-of-file
(eof, as defined by default is The special
command must be used.
Same as
Append a trailing
to all directory names resulting from file
name generation.
Same as
Same as
Same as
Same as
Do not save function definitions in history file.
Same as
Same as
Same as
Same as
Same as
Use a inline editor for command entry.
Process each character as it is typed in
mode (always on).
Same as
Disable processing of the
file and uses the file instead of the file. This mode is
on whenever the effective user ID (group ID) is not equal
to the real user ID (group ID). Turning this off causes
the effective user ID and group ID to be set to the real
user ID and group ID.
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.
Turn off
and options and stop examining arguments for options.
Do not change any of the options; useful in setting parameter
to a value beginning with If no arguments follow this
option, the positional parameters are unset.
%
Rename the positional parameters from to The default value of n
is n can be any arithmetic expression that evaluates to a non‐
negative number less than or equal to
Evaluate conditional expression expr. See test(1) for usage and
description. See also the subsection.
The arithmetic comparison operators are not restricted to inte‐
gers. They allow any arithmetic expression. The following
additional primitive expressions are allowed:
True if file is a symbolic link.
True if file exists.
True if file1 is newer than file2.
True if file1 is older than file2.
True if file1 has the same device and i-node num‐
ber as file2.
%
Print the accumulated user and system times for the shell and
for processes run from the shell.
%
Set arg as a command that is read and executed when the shell
receives a sig signal. (Note that arg is scanned once when the
trap is set and once when the trap is taken.) Each sig can be
given as the number or name of a signal. Letter case is
ignored. For example, and all specify the same signal. Use to
get a list of signals.
Trap commands are executed in signal number order. Any attempt
to set a trap on a signal that was ignored upon entering the
current shell is ineffective. Traps remain in effect for a
given shell until explicitly changed with another command; that
is, a trap set within a function will remain in effect even
after the function returns.
If arg is (or if arg is omitted and the first sig is numeric),
reset all traps for each sig to their original values.
If arg is the null string or ), each sig is ignored by the shell
and by the commands it invokes.
If sig is then arg is executed after each command. If sig is
arg is executed whenever a command has a nonzero exit code. If
sig is or the command arg is executed on exit from the shell.
With no arguments, print a list of commands associated with each
signal name.
&
Assign types and a value to a local named parameter name. See
also the special command. Parameter assignments remain in
effect after the command completes. When invoked inside a func‐
tion, create a new instance of the parameter name. The parame‐
ter value and type are restored when the function completes.
The following list of attributes can be specified. Use instead
of to turn the options off.
Left justify and remove leading blanks from
value. If n is nonzero, it defines the width of the
field; otherwise, it is determined by the width of the
value of first assignment. When name is assigned, the
value is filled on the right with blanks or truncated, if
necessary, to fit into the field. Leading zeros are
removed if the option is also set. The option is turned
off. Flagged as
Right justify and fill with leading blanks.
If n is nonzero, it defines the width of the field; oth‐
erwise, it is determined by the width of the value of
first assignment. The field is left-filled with blanks
or truncated from the end if the parameter is reassigned.
The option is turned off. Flagged as
Right justify and fill with leading zeros
if the first nonblank character is a digit and the option
has not been set. If n is nonzero it defines the width
of the field; otherwise, it is determined by the width of
the value of first assignment. Flagged as plus the flag
for or
Cause name to refer to function names rather than parameter
names. No assignments can be made to the name declared
with the statement. The only other valid options are
(which turns on execution tracing for this function) and
(which allows the function to remain in effect across
shell procedures executed in the same process environ‐
ment). Flagged as
Parameter is an integer.
This makes arithmetic faster. If n is nonzero it defines
the output arithmetic base; otherwise, the first assign‐
ment determines the output base. Flagged as
Convert all uppercase characters to lowercase.
The uppercase option is turned off. Flagged as
Mark any given
name as "read only". The name cannot be changed by sub‐
sequent assignment. Flagged as
Tag the named parameters.
Tags are user-definable and have no special meaning to
the shell. Flagged as
Convert all lowercase characters to uppercase characters.
The lowercase option is turned off. Flagged as
Mark any given
name for automatic export to the environment of subse‐
quently executed commands. Flagged as
alone displays a list of parameter names, prefixed by any flags
specified above.
displays the parameter names followed by their values. Specify
one or more of the option letters to restrict the list. Some
options are incompatible with others.
displays the parameter names alone. Specify one or more of the
option letters to restrict the list. Some options are incompat‐
ible with others.
Set or display a resource limit. The limit for a specified
resource is set when limit is specified. The value of limit can
be a number in the unit specified with each resource, or the
keyword
The and flags specify whether the hard limit or the soft limit
is set for the given resource. A hard limit cannot be increased
once it is set. A soft limit can be increased up to the hard
limit. If neither nor is specified, the limit applies to both.
The current resource limit is printed when limit is omitted. In
this case, the soft limit is printed unless is specified. When
more than one resource is specified, the limit name and unit are
printed before the value.
If no option is given, is assumed.
List all of the current resource limits.
The number of 512-byte blocks in the size of core dumps.
The number of kilobytes in the size of the data area.
The number of 512-byte blocks in files written by child pro‐
cesses
(files of any size can be read).
The number of file descriptors.
The number of kilobytes in the size of the stack area.
The number of seconds to be used by each process.
Set the user file-creation mask mask. mask can be either an
octal number or a symbolic value as described in umask(1). A
symbolic value shows permissions that are unmasked. An octal
value shows permissions that are masked off.
Without mask, print the current value of the mask. With print
the value in symbolic format. Without print the value as an
octal number. The output from either form can be used as the
mask of a subsequent invocation of
Remove each name from the alias list. With remove all defini‐
tions from the current shell execution environment. See also
the special command.
%
Remove the named shell parameters from the parameter list.
Their values and attributes are erased. Read-only variables
cannot be unset. With names refer to function names. With
names refer to variable names. Unsetting and removes their spe‐
cial meaning, even if they are subsequently assigned to.
Wait for the specified job to terminate or stop, and report its
status. This status becomes the return code for the command.
Without job, wait for all currently active child processes to
terminate and returns with a zero exit status. See the subsec‐
tion for a description of the format of job.
For each name, indicate how it would be interpreted if used as a
command name. With produce a more verbose report. With do a
path search for name, disregarding any use as an alias, a func‐
tion, or a reserved word.
Comments
A beginning with causes that word and all the following characters up
to a newline to be ignored.
Aliasing
The first word of each command is replaced by the text of an if an for
this word has been defined. An name consists of any number of charac‐
ters excluding metacharacters, quoting characters, file expansion char‐
acters, parameter and command substitution characters, and =. The
replacement string can contain any valid shell script, including the
metacharacters listed above. The first word of each command in the
replaced text, other than any that are in the process of being
replaced, will be tested for additional aliases. If the last character
of the alias value is a the word following the alias is also checked
for alias substitution. Aliases can be used to redefine special com‐
mands, but cannot be used to redefine the keywords listed in the sub‐
section. Aliases can be created, listed, and exported with the command
and can be removed with the command. Exported aliases remain in effect
for subshells but must be reinitialized for separate invocations of the
shell (see the subsection).
Aliasing is performed when scripts are read, not while they are exe‐
cuted. Therefore, for it to take effect, an must be executed before
the command referring to the alias is read.
Aliases are frequently used as a shorthand for full path names. An
option to the aliasing facility allows the value of the alias to be
automatically set to the full path name of the corresponding command.
These aliases are called aliases. The value of a tracked alias is
defined the first time the identifier is read and becomes undefined
each time the variable is reset. These aliases remain tracked so that
the next reference will redefine the value. Several tracked aliases
are compiled into the shell. The option of the command converts each
command name that is an into a tracked alias.
The following are compiled into the shell but can be unset or rede‐
fined:
Tilde Substitution
After alias substitution is performed, each word is checked to see if
it begins with an unquoted tilde If it does, the word up to a is
checked to see if it matches a user name in the file. If a match is
found, the and the matched login name are replaced by the login direc‐
tory of the matched user. If no match is found, the original text is
left unchanged. A alone or before a is replaced by the value of the
parameter. A followed by a or is replaced by the value of the parame‐
ter and respectively. In addition, tilde substitution is attempted
when the value of a parameter assignment begins with a
Command Substitution
The standard output from a command enclosed in parenthesis preceded by
a dollar sign or a pair of grave accents can be used as part or all of
a word; trailing newlines are removed. In the second (archaic) form,
the string between the accents is processed for special quoting charac‐
ters before the command is executed. See the subsection. The command
substitution can be replaced by the equivalent but faster Command sub‐
stitution of most special commands that do not perform input/output re‐
direction are carried out without creating a separate process.
An arithmetic expression enclosed in double parenthesis preceded by a
dollar sign is replaced by the value of the arithmetic expression
within the double parenthesis. See the subsection for a description of
arithmetic expressions.
Parameter Substitution
A is an identifier, one or more decimal digits, or one of the charac‐
ters and A (a parameter denoted by an identifier) has a value and zero
or more attributes. Named parameters can be assigned values and
attributes with the special command. Exported parameters pass values
and attributes to the environment.
The shell supports a limited one-dimensional array facility. An ele‐
ment of an array parameter is referenced by a subscript. A subscript
is denoted by a followed by an arithmetic expression, followed by a See
the subsection. To assign values to an array, use The value of all
subscripts must be in the range of through Arrays need not be declared.
Any reference to a named parameter with a valid subscript is legal and
an array is created if necessary. Referencing an array parameter with‐
out a subscript is equivalent to referencing the first element.
If the integer attribute is set for name, the value is subject to
arithmetic evaluation.
Positional parameters, parameters denoted by a number, can be assigned
values with the special command. Parameter is set from argument zero
when the shell is invoked.
Use the prefix character to specify the value of a parameter for sub‐
stitution.
Substitute the value of the parameter, if any.
Braces are required when parameter is fol‐
lowed by a letter, digit, or underscore
that should not be interpreted as part of
its name or when a named parameter is sub‐
scripted. If parameter is one or more
digits, it is a positional parameter. A
positional parameter of more than one
digit must be enclosed in braces. The
shell reads all the characters from to the
matching as part of the same word, even if
it contains braces or metacharacters.
If parameter is or all the positional
parameters, starting with are substituted
(separated by a field separator charac‐
ter). See the subsection.
If an array parameter with subscript or is
used, the value for each element is sub‐
stituted (separated by a field separator
character).
If parameter is or the number of positional
parameters is substituted. Otherwise, the
length of the value of the parameter is
substituted.
Substitute the number of elements in the array.
If parameter is set and is nonnull, substi‐
tute its value; otherwise, substitute
word.
If parameter is not set or is null, set it to
word; then substitute the value of the
parameter. Positional parameters may not
be assigned in this way.
If parameter is set and is nonnull, substi‐
tute its value; otherwise, print word and
exit from the shell. If word is omitted,
a standard message is printed.
If parameter is set and is nonnull, substi‐
tute word; otherwise, substitute nothing.
If the shell pattern matches the beginning of
the value of parameter, the value
of this substitution is the value
of the parameter with the matched
portion deleted; otherwise, the
value of this parameter is substi‐
tuted. In the former case, the
smallest matching pattern is
deleted; in the latter case, the
largest matching pattern is
deleted. These characters, or
should be escaped by a backslash
(\) or quotes ('').
If the shell pattern matches
the end of the value of
parameter, the value of
parameter with the matched
part is deleted; otherwise,
substitute the value of
parameter. In the former,
the smallest matching pat‐
tern is deleted; in the lat‐
ter, the largest matching
pattern is deleted. These
characters, or should be
escaped by a backslash (\)
or quotes ('').
In the above, word is not evaluated unless
it is used as the substituted string.
Thus, in the following example, is executed
only if is not set or is null:
If the colon is omitted from the above
expressions, the shell only checks to
determine whether or not parameter is set.
· The following parameters are set automat‐
ically by the shell:
The string used to call the command or
script,
set from invocation argument
zero.
The positional parameters.
All the set positional parameters, sepa‐
rated by a field separator character.
See the subsection.
The number of set positional parameters in
decimal.
Flags supplied to the shell on invocation
or by the
command.
The decimal exit status returned by the
last executed command.
The process number of this shell.
Initially, the absolute path name of
the shell or script being
executed, as passed in the
environment. Subsequently,
it is assigned 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 match‐
ing file when checking for
mail.
The process number of the last background
command invoked.
The value of as set by the most recently
failed system call. This
value is system-dependent
and is intended for debug‐
ging purposes.
The line number of the current line within
the script or
function being executed.
The previous working directory set by the
command.
The value of the last option argument pro‐
cessed by the
special command.
If set to 0, will suppress error messages
from the special command.
is initially set to 1.
The index of the last option argument pro‐
cessed by the
special command.
The process number of the parent of the
shell.
The present working directory set by the
command.
Each time this parameter is evaluated, a
random integer,
uniformly distributed
between 0 and 32767, is gen‐
erated. The sequence of
random numbers can be ini‐
tialized by assigning a
numeric value to
Set by the compound command, and by the
special command when no name
is supplied.
Each time this parameter is referenced,
the number of seconds since
shell invocation is
returned. If this parameter
is assigned a value, the
value returned upon refer‐
ence is the value that was
assigned plus the number of
seconds since the assign‐
ment.
· The following parameters are used by the
shell:
The search path for the
command, a list of directo‐
ries separated by colons.
If this variable is set,
its value is used to define
the width of the edit window
for the shell edit modes and
for printing lists.
If the value of this variable ends in
or and the variable is not
set, the corresponding
option is turned on (see the
special command.
If this parameter is set,
parameter substitution is
performed on the value to
generate the path name of
the script to be executed
when the shell is invoked
(see the subsection). This
file is typically used for
and definitions.
By default, script is exe‐
cuted for interactive shells
only. Under the environment
(see standards(5)), this
file is executed for both
interactive and non-interac‐
tive shells.
The default editor name for the
command.
The search path for function definitions,
a list of directories sepa‐
rated by colons. This path
is searched when a function
with the attribute is refer‐
enced and when a command is
not found. If an executable
file is found, then it is
read and executed in the
current environment.
If this parameter is set when the shell is
invoked,
its value is the path name
of the file that is used to
store the command history.
The default value is If the
user is a superuser and no
is given, then no history
file is used. See the sub‐
section and the section.
If this parameter is set when the shell is
invoked,
the number of previously
entered commands accessible
to this shell will be
greater than or equal to
this number. The default is
128.
The default argument (home directory) for
the
command.
Internal field separators,
normally space, tab, and
newline, that are used to
separate command words
resulting from command or
parameter substitution and
for separating words with
the special command The
first character of the
parameter is used to sepa‐
rate arguments for the sub‐
stitution (see the subsec‐
tion). If the value of is
space, tab, and newline, or
if is unset and it is being
used to separate the results
of command or parameter sub‐
stitution, any sequence of
characters serves to delimit
words; otherwise, each
occurrence of a character in
serves to delimit a word.
If the value of is null, no
word splitting is done.
The locale of your system, which is made up
of three parts:
language, territory, and
code set. The default is
the locale. See environ(5).
The overriding value for
and the variables. See env‐
iron(5).
The collating sequence to use when sorting
names and
when character ranges occur
in patterns. See envi‐
ron(5).
The character classification information to
use.
Changing the value of after
the shell has started does
not affect the lexical pro‐
cessing of shell commands in
the current shell execution
environment or its sub‐
shells. See environ(5).
The shell uses to detect
nonprintable characters in
the input and tries to han‐
dle them when the or editing
mode is selected. Not
starting a new shell session
after setting may affect the
display of nonprintable
input characters in the or
editing mode.
The language in which system messages
appear,
and the language that the
system expects for user
input of and strings. See
environ(5).
The currency symbol and monetary value for‐
mat.
See environ(5).
The numeric format.
See environ(5).
The date and time format.
See environ(5).
If this variable is set,
the value is used to deter‐
mine the column length for
printing lists. lists print
vertically until about two-
thirds of lines are filled.
If this parameter is set to the name of a
mail file
and the parameter is not
set, the shell informs the
user of arrival of mail in
the specified file.
How often (in seconds)
the shell checks for changes
in the modification time of
any of the files specified
by the or parameters. The
default value is 600 sec‐
onds. When the time has
elapsed, the shell checks
before issuing the next
prompt.
A list of file names separated by colons.
If this parameter is set,
the shell informs the user
of any modifications to the
specified files that have
occurred within the last
seconds. Each file name can
be followed by a and a mes‐
sage to be printed, in which
case the message will
undergo parameter and com‐
mand substitution with the
parameter defined as the
name of the changed file.
The default message is
The search path for message catalogs,
a list of directories sepa‐
rated by colons.
The search path for commands, a list of
directories separated by colons.
See the subsection.
The value of this parameter is expanded for
parameter
substitution, to define the
primary prompt string. The
default value is "". The
character in the primary
prompt string is replaced by
the command number. See the
subsection.
Secondary prompt string for command comple‐
tion.
The default value is "".
Selection prompt string used within a
loop. If unset, it defaults
to "".
Execution trace string that precedes each
line of an execution trace.
See the special command. If
unset, it defaults to "".
The path name of the shell is kept in the
environment.
When invoked, the shell is
restricted if the value of
this variable contains an in
the base name.
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
prompt. (Note that the
shell can be compiled with a
maximum bound for this value
which cannot be exceeded.)
Invokes the corresponding option when the
value of this variable ends in
or See the special command.
The shell gives default values to and On
the other hand, and are never set automati‐
cally by the shell (although and are set by
see login(1)).
Blank Interpretation
After parameter and command substitution,
the results of substitution are scanned for
field separator characters (defined in and
split into distinct arguments when such
characters are found. retains explicit
null arguments (or but removes implicit
null arguments (those resulting from param‐
eters that have null values).
File Name Generation
Following substitution, each command word
is processed as a pattern for file name
expansion unless expansion has been dis‐
abled with the special command. The form
of the patterns is the defined in reg‐
exp(5). The word is replaced with sorted
file names matching the pattern. If no
file name is found that matches the pat‐
tern, the word is left unchanged.
In addition to the notation described in
regexp(5), recognizes composite patterns
made up of one or more patterns separated
from each other with a Composite patterns
can be formed with one or more of the fol‐
lowing:
Matches any one of the given pat‐
terns.
Matches zero or more occurrences of
the given patterns.
Matches one or more occurrences of
the given patterns.
Matches exactly one of the given
patterns.
Matches anything, except one of the
given patterns.
Quoting
Each of the metacharacters (see the subsec‐
tion) has a special meaning to the shell
and terminates a word unless quoted. A
character may be (that is, made to stand
for itself) by preceding it with a back‐
slash The pair is ignored; the current and
following lines are concatenated.
All characters enclosed between a pair of
apostrophes are quoted. An apostrophe can‐
not appear within apostrophes.
Parameter and command substitution occurs
inside quotation marks (...). quotes the
characters , and
Inside grave accent marks quotes the char‐
acters and If the grave accents occur
within quotation marks, also quotes the
character .
The meanings of and are identical when not
quoted or when used as a parameter assign‐
ment value or as a file name. However,
when used as a command argument, is equiva‐
lent to , whereas is equivalent to dd...
(where d is the first character of
The special meaning of keywords or aliases
can be removed by quoting any character of
the name. The recognition of function
names or special command names cannot be
altered by quoting them.
Arithmetic Evaluation
Integer arithmetic is provided with the
special command Evaluations are performed
using long integer arithmetic. Constants
take the form or n, where base is a decimal
number between two and thirty-six repre‐
senting the arithmetic base and n is a num‐
ber in that base. If is omitted, base 10
is used.
An arithmetic expression uses the same syn‐
tax, precedence, and associativity of
expression as the C language. All the
integral operators, other than and are sup‐
ported. Variables can be referenced by
name within an arithmetic expression with‐
out using the parameter substitution syn‐
tax. When a variable is referenced, its
value is evaluated as an arithmetic expres‐
sion.
A variable can be typed as an integer with
the option of the special command, as in
Arithmetic evaluation is performed on the
value of each assignment to a variable with
the attribute. If you do not specify an
arithmetic base, the first assignment to
the variable determines the arithmetic
base. This base is used when parameter
substitution occurs.
Since many of the arithmetic operators
require quoting, an alternative form of the
command is provided. For any command
beginning with all characters until the
matching are treated as a quoted expres‐
sion. More precisely, is equivalent to
....
Arithmetic expressions given with command,
and will be processed according to ISOC
standard with the exception of and opera‐
tors.
Prompting
When used interactively, the shell prompts
with the value of before reading a command.
Whenever a newline is received and further
input is needed to complete a command, the
secondary prompt (the value of is issued.
Conditional Expressions
A is used with the compound command to test
attributes of files and to compare strings.
Word splitting and file name generation are
not performed on the words between and (See
also the special command.) Each expression
can be constructed from one or more of the
following unary or binary expressions:
True, if file exists.
True, if file exists and
is a block spe‐
cial file.
True, if file exists and
is a character
special file.
True, if file exists and
is a directory.
True, if file exists.
True, if file exists and
is an ordinary
file.
True, if file exists and
has its setgid
bit set.
True, if file exists and
is a symbolic
link.
True, if file exists and
has its sticky
bit set.
True, if length of string is
nonzero.
True, if the set option named
option is on.
True, if file exists and
is a fifo spe‐
cial file or a
pipe.
True, if file exists and
is readable by
current process.
True, if file exists and
has a size
greater than
zero.
True, if file descriptor number
fildes is open
and is associ‐
ated with a ter‐
minal device.
True, if file exists and
has its setuid
bit set.
True, if file exists and
is writable by
the current
process.
True, if file exists and
is executable by
the current
process. If
file exists and
is a directory,
then the current
process has per‐
mission to
search in the
directory.
True, if length of string is zero.
True, if file exists and
is a symbolic
link.
True, if file exists and
is owned by the
effective user
ID of this
process.
True, if file exists and
its group
matches the
effective group
ID of this
process.
True, if file exists and
is a socket.
True, if file1 exists and
is newer than
file2.
True, if file1 exists and
is older than
file2.
True, if file1 and file2
exist and refer
to the same
file.
True, if string matches
pattern.
True, if string does not
match pattern.
True, if string1 comes
before string2
based on the
ASCII value of
their charac‐
ters.
True, if string1 comes
after string2
based on the
ASCII value of
their charac‐
ters.
True, if exp1 is equal to
exp2.
True, if exp1 is not
equal to exp2.
True, if exp1 is less
than exp2.
True, if exp1 is greater
than exp2.
True, if exp1 is less
than or equal to
exp2.
True, if exp1 is greater
than or equal to
exp2.
A compound expression can be constructed
from these primitives by using any of the
following, listed in decreasing order of
precedence.
True, if exp is true.
Used to group
expressions.
True, if exp is false.
True, if exp1 and exp2
are both true.
True, if either exp1 or exp2 is
true.
Input/Output
Before a command is executed, its input and
output can be redirected using a special
notation interpreted by the shell. The
following can appear anywhere in a simple-
command or may precede or follow a command
and are not passed on to the invoked com‐
mand. Command and parameter substitution
occurs before word or digit is used, except
as noted below. File name generation
occurs only if the pattern matches a single
file and blank interpretation is not per‐
formed.
Use file word as standard
input (file descrip‐
tor
Use file word as standard out‐
put (file descriptor
If the file does not
exist, it is created.
If the file exists,
and the option is on,
an error occurs; oth‐
erwise, the file is
truncated to zero
length. Note that
the test is only
applied to regular
files, not to named
pipes or other file
types.
Same as except that it over‐
rides the option.
Use file word as standard out‐
put. If the file
exists, output is
appended to it (by
first searching for
the end-of-file);
otherwise, the file
is created.
Open file word for reading and
writing as standard
input.
The shell input is read up to a line
that matches
word, or to an end-
of-file. No parame‐
ter substitution,
command substitution
or file name genera‐
tion is performed on
word. The resulting
document, called a
becomes the standard
input. See also the
section.
If any character of
word is quoted, no
interpretation is
placed upon the char‐
acters of the docu‐
ment. Otherwise,
parameter and command
substitution occurs,
is ignored, and must
be used to quote the
characters and the
first character of
word.
If is appended to all
leading tabs are
stripped from word
and from the docu‐
ment.
The standard input is duplicated
from file descriptor
digit (see dup(2)).
The standard output is duplicated to
file descriptor
digit (see dup(2)).
The standard input is closed.
The standard output is closed.
The input from the coprocess is
moved to standard input.
The output to the coprocess is moved
to standard output.
If any of the above redirections is pre‐
ceded by a digit to the file descriptor
used is the one specified by the digit,
instead of the default (standard input) or
(standard output). For example:
means open file descriptor 2 for writing as
a duplicate of file descriptor 1. Output
directed to file descriptor 2 is written in
the same location as output to file
descriptor 1.
Order is significant in redirection. The
shell evaluates each redirection in terms
of the (file descriptor, file) assignment
at the time of evaluation. For example:
first assigns file descriptor 1 to file
fname. It then assigns file descriptor 2
to the file assigned to file descriptor 1
(that is, fname).
If the order of redirection is reversed, as
in
file descriptor 2 is assigned to the file
assigned to file descriptor 1 (probably the
terminal) and then file descriptor 1 is
assigned to file fname.
By using the redirection operators above,
the input and output of a coprocess may be
moved to a numbered file descriptor, allow‐
ing other commands to write to them and
read from them. If the input of the cur‐
rent coprocess is moved to a numbered file
descriptor, another coprocess may be
started.
If a command is followed by and job control
is inactive, the default standard input for
the command is the empty file Otherwise,
the environment for the execution of a com‐
mand contains the file descriptors of the
invoking shell as modified by input/output
specifications.
Environment
The (see environ(5)) is a list of name-
value pairs passed to an executed program
much like a normal argument list. The
names must be identifiers and the values
are character strings. The shell interacts
with the environment in several ways. When
invoked, the shell scans the environment
and creates a parameter for each name
found, gives it the corresponding value and
marks it Executed commands inherit the
environment. If the user modifies the val‐
ues of these parameters or creates new ones
by using the or special commands, the val‐
ues become part of the environment. The
environment seen by any executed command is
thus composed of any name-value pairs orig‐
inally inherited by the shell, whose values
may be modified by the current shell, plus
any additions which must be noted in or
commands.
The environment for any simple command or
function can be augmented by prefixing it
with one or more parameter assignments. A
parameter assignment argument takes the
form For example, both the following
are equivalent (as far as the execution of
cmd is concerned, except for the special
commands that are preceded by a percent
sign (%).
If the option is set, all parameter assign‐
ment arguments are placed in the environ‐
ment, even if they occur after the command
name. The following echo statement prints
After the option is set, the second echo
statement prints only
This feature is intended for use with
scripts written for early versions of the
shell and its use in new scripts is
strongly discouraged. It is likely to dis‐
appear someday.
Functions
The command (described in the subsection)
defines shell functions. Shell functions
are read and stored internally. Alias
names are resolved when the function is
read. Functions are executed like com‐
mands, with the arguments passed as posi‐
tional parameters. (See the subsection.)
Functions execute in the same process as
the caller and share all files and current
working directory with the caller. Traps
defined by the caller remain in effect
within the function until another command
is executed. Traps set within a function
remain in effect after the function
returns. Ordinarily, variables are shared
between the calling program and the func‐
tion. However, the special command can be
used within a function to define local
variables whose scope includes the current
function and all functions it calls.
The special command is used to return from
function calls. Errors within functions
return control to the caller.
Function identifiers can be listed with the
option of the special command. Function
identifiers and the associated text of the
functions can be listed with the option.
Functions can be undefined with the option
of the special command.
Ordinarily, functions are unset when the
shell executes a shell script. The option
of the command allows a function to be
exported to scripts that are executed with‐
out reinvoking the shell. Functions that
must be defined across separate invocations
of the shell should be placed in the file.
Jobs
If the option of the command is turned on,
an interactive shell associates a job 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 that looks like:
indicating that job number 1 was started
asynchronously and had one (top-level)
process whose process ID was 1234.
If you are running a job and wish to do
something else, you can type the suspend
character (the character defined with see
stty(1)) to send a signal to the current
job. The shell then indicates that the job
has been and prints another prompt. Then
you can manipulate the state of this job by
putting it in the background with the com‐
mand, running other commands, and eventu‐
ally returning the job to the foreground
with the command. A suspend takes effect
immediately and resembles an interrupt,
since pending output and unread input are
discarded when the suspend is entered.
A job running in the background stops if it
tries to read from the terminal. Back‐
ground jobs normally are allowed to produce
output, but can be disabled with the com‐
mand. If the user sets this terminal
option, background jobs stop when trying to
produce output.
There are several ways to refer to jobs in
the shell. A job can be referred to by the
process ID of any process in the job or by
one of the following:
The job with the given number.
Any job whose command line begins
with
string.
Any job whose command line contains
string.
Current job.
Equivalent to
Previous job.
The shell learns immediately when a process
changes state. It informs the user when a
job is blocked and prevented from further
progress, but only just before it prints a
prompt.
When the monitor mode is on, each back‐
ground job that completes triggers any trap
set for
If you try to exit from shell while jobs
are stopped, you are warned with the mes‐
sage You can use the command to identify
them. If you immediately try to exit
again, the shell will not warn you a second
time, and the stopped jobs will be termi‐
nated.
If you try to leave the shell while jobs
are running, you are not warned. The shell
exits silently and sets the parent of the
running jobs to the process (number 1).
Signals
The and signals for an invoked command are
ignored if the command is followed by and
the option is off. Otherwise, signals have
the values inherited by the shell from its
parent, with the exception of signal (but
see also the special command).
Execution
Substitutions are made each time a command
is executed. checks the command name to
determine whether it matches a special com‐
mand. If it does, it is executed within
the current shell process.
Next, checks the command name to determine
whether it matches one of the user-defined
functions. If it does, saves the posi‐
tional parameters, then sets them to the
arguments of the function call. The posi‐
tional parameter is unchanged. When the
function completes or issues a restores the
positional parameter list. The value of a
function is the value of the last command
executed. A function is executed in the
current shell process.
If a command name is not a user-defined
function or a special command, creates a
process and attempts to execute the command
using an system call (see exec(2)).
The shell parameter defines the search path
for the directory containing the command.
Alternative directory names are separated
by a colon The default path is (specifying
and the current directory, in that order).
Note that the current directory is speci‐
fied by a null path name, which can appear
immediately after the equal sign, between
colon delimiters, or at the end of the path
list. The search path is not used if the
command name contains a Otherwise, each
directory in the path is searched for an
executable file. If the file has execute
permissions but is not a directory or an
executable object code file, it is assumed
to be a script file, which is a file of
data for an interpreter. If the first two
characters of the script file are expects
an interpreter path name to follow. then
attempts to execute the specified inter‐
preter as a separate process to read the
entire script file. If a call to fails, is
spawned to interpret the script file. All
nonexported aliases, functions, and named
parameters are removed in this case. If
the shell command file does not have read
permission, or if the and/or bits are set
on the file, the shell executes an agent to
set up the permissions and execute the
shell with the shell command file passed
down as an open file. A parenthesized com‐
mand is also executed in a subshell without
removing nonexported quantities.
Command Reentry
The text of the last (default 128) commands
entered from a terminal device is saved in
a history file. The file is used if the
variable is not set or writable. A shell
can access the commands of all interactive
shells that use the same named The special
command is used to list or edit a portion
of this file. The portion of the file to
be edited or listed can be selected by num‐
ber or by giving the first character or
characters of the command. A single com‐
mand or range of commands can be specified.
If you do not specify an editor program as
an argument to the value of the parameter
is used. If is not defined, is used. The
edited command is printed and reexecuted
upon leaving the editor. The editor name
is used to skip the editing phase and to
reexecute the command. In this case, a
substitution parameter of the form can be
used to modify the command before execu‐
tion. For example, if is aliased to typing
reexecutes the most recent command that
starts with the letter and replaces the
first occurrence of the string with the
string
The history file will be trimmed when all
of the following conditions occurs:
Its size is greater than four kilo‐
bytes.
The number of commands in it is more
than
The file has not been modified in
the last ten minutes.
The user has write permission for
the directory in which the history
file resides.
If any one of the above conditions does not
occur, the history file will not be
trimmed. When the history file is trimmed,
the latest commands will be available in
the history file.
Command Line Editing
Normally, each command line typed at a ter‐
minal device is followed by a newline or
return. If one of the or options is set,
you can edit the command line. An editing
option is automatically selected each time
the or variable is assigned a value ending
in one of these option names.
The editing features require that the
user's terminal accept return without line
feed and that a space (" ") must overwrite
the current character on the screen. ADM
terminal users should set the
"space − advance" switch to "space".
Hewlett-Packard terminal users should set
the straps to "bcGHxZ etX".
The editing modes enable the user to look
through a window at the current line. The
default window width is 80, unless the
value of is defined. If the line is longer
than the window width minus two, a mark
displayed at the end of the window notifies
the user. The mark is one of:
The line extends to the right.
The line extends to the left.
The line extends to both sides of
the window.
As the cursor moves and reaches the window
boundaries, the window is centered about
the cursor.
The search commands in each edit mode pro‐
vide access to the history file. Only
strings are matched, not patterns, although
a leading in the string restricts the match
to begin at the first character in the
line.
Changing the environment variable can
affect the editors. See the subsection.
emacs/gmacs Editing Mode
This mode is invoked by either the or
option. The sole difference is how they
handle Control-T.
To edit, the user moves the cursor to the
point needing correction and inserts or
deletes characters or words. All editing
commands are control characters or escape
sequences. The notation for control char‐
acters is caret followed by a character.
For example, is the notation for Control-F.
This is entered by holding down the Ctrl
(control) key and pressing The shift key is
pressed. The notation indicates the delete
(DEL) key.
The notation for escape sequences is fol‐
lowed by a character. For example, (pro‐
nounced is entered by pressing the escape
key (followed by pressing is the notation
for escape followed by shift (capital)
All edit commands operate from any place on
the line (not only at the beginning). Nei‐
ther the return nor the newline 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, dig‐
its 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.
Move cursor forward to character
char on current line.
Move cursor backward to character
char on current line.
Interchange the cursor and mark.
erase Delete previous char‐
acter. The erase
character is user-
definable with the
command; it is usu‐
ally set to The sys‐
tem default is
Delete current character.
eof Terminate the shell
if the current line
is null. The eof
character is user-
definable with the
command; it is usu‐
ally set to The sys‐
tem default is
Delete current word.
Delete previous word (meta-
backspace).
Delete previous word.
Delete previous word (meta-delete).
If your interrupt
character is (DEL,
the default), this
command will not
work.
In mode, transpose cur‐
rent character with
next character. In
mode, transpose two
previous characters.
Capitalize current character.
Capitalize current word.
Change the current word to lower‐
case.
Delete from the cursor to the end of
the line.
If preceded by a
numerical parameter
whose value is less
that the current cur‐
sor position, then
delete from the given
position up to the
cursor. If preceded
by a numerical param‐
eter whose value is
greater than the cur‐
rent cursor position,
then delete from the
cursor up to the
given position.
Kill from the cursor to the mark.
Push the region from the cursor to
the mark on the stack.
kill Kill the entire cur‐
rent line. If two
kill characters are
entered in succes‐
sion, all subsequent
consecutive kill
characters cause a
line feed (useful
when using paper ter‐
minals). The kill
character is user-
definable with the
command; it is usu‐
ally set to or The
system default is
Restore last item removed from line
(yank item back to
the line).
Line feed and print current line.
Set mark (null character).
Set mark (meta-space).
Execute the current line
(newline).
Execute the current line
(return).
Fetch previous command.
Each time is entered,
the previous command
in the history list
is accessed.
Fetch next command.
Each time is entered
the next command in
the history list is
accessed.
Fetch the least recent (oldest) his‐
tory line.
Fetch the most recent (youngest)
history line.
Reverse search history for a previ‐
ous command line containing
string. If a parame‐
ter of zero is given,
the search is for‐
ward. string is ter‐
minated by a return
or newline. If
string is preceded by
a the matched line
must begin with
string. If string is
omitted, the next
command line contain‐
ing the most recent
string is accessed.
In this case, a
parameter of zero
reverses the direc‐
tion of the search.
Execute the current line
and fetch the next
line relative to cur‐
rent line from the
history file.
Define a numeric parameter.
The digits are taken
as a parameter to the
next command. The
commands that accept
a parameter are
erase, and
Your alias list is searched for an
alias by the name
(underscore-letter).
If an alias of this
name is defined, its
value is inserted on
the input queue.
This letter must not
be one of the above
metafunctions.
The last word of the previous com‐
mand is inserted on the line.
If preceded by a
numeric parameter,
the value of this
parameter determines
which word to insert
rather than the last
word.
Same as
Attempt file name generation on the
current word.
File name completion
(meta-escape).
Replaces the current
word with the longest
common prefix of all
file names matching
the current word with
an asterisk appended.
If the match is
unique, a is appended
if the file is a
directory and a space
is appended if the
file is not a direc‐
tory.
List files matching current word
pattern
as if an asterisk
were appended.
Multiply parameter of next command
by 4.
Escape next character.
Editing characters
and your erase, kill,
and interrupt charac‐
ters may be entered
in a command line or
in a search string,
if preceded by a The
removes the next
character's editing
features (if any).
Display version of the shell.
Insert a at the beginning of
the line and execute
it. This causes a
comment to be
inserted in the his‐
tory file.
vi Editing Mode
The editor starts in insert mode until an
escape (ESC) is received. This puts you in
control mode in which you can move the cur‐
sor and perform editing commands. A return
in either mode sends the line.
Most control commands accept an optional
repeat count prior to the command.
In mode on most systems, canonical process‐
ing is initially enabled and the command is
echoed again if the speed is 1200 baud or
greater and contains any control charac‐
ters, or if less than one second has
elapsed since the prompt was printed. The
escape (ESC) character terminates canonical
processing for the remainder of the command
and you can then modify the command line.
This scheme has the advantages of canonical
processing with the typeahead echoing of
raw mode.
Setting the option always disables canoni‐
cal processing on the terminal. This mode
is implicit for systems that do not support
two alternate end-of-line delimiters, and
may be helpful for certain terminals. By
default, the editor is in insert mode.
erase Delete previous
inserted character.
The erase character
is user-definable
with the command; it
is usually set to The
system default is
kill Delete all current
inserted characters.
The kill character is
user-definable with
the command; it is
usually set to or The
system default is
Escape the next
erase or kill charac‐
ter.
eof Terminate the shell
if the current line
is null. The eof
character is user-
definable with the
command; it is usu‐
ally set to The sys‐
tem default is
Escape next character.
Editing characters
and erase or kill
characters may be
entered in a command
line or in a search
string if preceded by
a which removes the
next character's
editing features (if
any).
Delete the previous blank-separated
word.
These commands move the cursor. The use of
count causes a repetition of the command
the cited number of times.
Cursor forward (right) one charac‐
ter.
Cursor forward one alphanumeric
word.
Cursor forward to the beginning of
the next word that follows a blank.
Cursor forward to the end of the
word.
Cursor forward to end of the current
blank-delimited word.
Cursor backward (left) one charac‐
ter.
Cursor backward one word.
Cursor backward to preceding blank-
separated word.
Cursor to column
count. Default is 1.
Find the next character
c in the current
line.
Find the previous character
c in the current
line.
Equivalent to followed by
Equivalent to followed by
Repeat the last single-character
find command,
or
Reverses the last single character
find command.
Cursor to start of line.
Cursor to first nonblank character
in line.
Cursor to end of line.
These commands access your command history
file.
Fetch previous command.
Each time is entered,
the next earlier com‐
mand in the history
list is accessed.
Equivalent to
Fetch next command.
Each time is entered,
the next later com‐
mand in the history
list is accessed.
Equivalent to
The command number
count is fetched.
The default is the
first command in the
history list.
Search backward through history for
a previous command containing
string. string is
terminated by a
return or newline.
If string is preceded
by a the matched line
must begin with
string. If string is
null, the previous
string is used.
Same as but search in the
forward direction.
Search for next match of the last
pattern to the
or commands.
Search for next match of the last
pattern to
or but in reverse
direction.
These commands will modify the line.
Enter insert mode after the current
character.
Append text to the end of the line.
Equivalent to
Move cursor forward to
the character position
specified by
motion,
delet‐
ing all
charac‐
ters
between
the
origi‐
nal
cursor
posi‐
tion
and the
new
posi‐
tion,
and
enter
insert
mode.
If
motion
is the
entire
line is
deleted.
Delete from the cur‐
rent character through
the end of line
and
enter
insert
mode.
Equiva‐
lent to
Equivalent to
Move
cursor
to the
charac‐
ter
position
speci‐
fied by motion,
delet‐
ing
all
char‐
ac‐
ters
between
the
orig‐
i‐
nal
cur‐
sor
posi‐
tion
and
the
new
posi‐
tion.
If
motion
is
the
entire
line
will
be
deleted.
Delete
from the
current
charac‐
ter
through
the end
of line. Equiv‐
a‐
lent
to
Enter
insert
mode
before
the cur‐
rent
charac‐
ter.
Enter
insert
mode
before
the
begin‐
ning of
the
line. Equiv‐
a‐
lent
to
the
two-
char‐
ac‐
ter
sequence
Insert
the pre‐
vious
text
modifi‐
cation
before
the cur‐
sor.
Insert
the pre‐
vious
text
modifi‐
cation
after
the cur‐
sor.
Enter
insert
mode and
replace
charac‐
ters on
the
screen with
char‐
ac‐
ters
you
type,
over‐
lay
fash‐
ion.
Replace
the cur‐
rent
charac‐
ter with c.
Delete
the cur‐
rent
charac‐
ter.
Delete
the pre‐
ceding
charac‐
ter.
Repeat
the pre‐
vious
text
modifi‐
cation
command.
Invert
the case
of the
current
charac‐
ter and
advance
the cur‐
sor.
Append
the count
word
of
the
pre‐
vi‐
ous
com‐
mand
at
the
cur‐
rent
cur‐
sor
loca‐
tion
and
enter
insert
mode
at
the
end
of
the
appended
text.
The
last
word
is
used
if
count
is
omit‐
ted.
Append
an to
the
cur‐
rent
word
and
attempt
file
name
gen‐
er‐
a‐
tion.
If
no
match
is
found,
ring
the
bell.
If
a
match
is
found,
replace
the
word
with
the
match‐
ing
string
of
file
names
and
enter
insert
mode.
escape
Attempt
file
name
comple‐
tion on
the cur‐
rent
word. Replace
the
cur‐
rent
word
with
the
long‐
est
com‐
mon
pre‐
fix
of
all
file
names
match‐
ing
the
cur‐
rent
word
with
an
aster‐
isk
appended.
If
the
match
is
unique,
append
a
if
the
file
is
a
direc‐
tory
or
append
a
space
if
the
file
is
not
a
direc‐
tory.
Yank
cur‐
rent
char‐
ac‐
ter
through
char‐
ac‐
ter
that motion
would
move
the
cur‐
sor
to
and
put
them
into
the
delete
buf‐
fer.
The
text
and
cur‐
sor
are
unchanged.
Yank
from
cur‐
rent
posi‐
tion
to
end
of
line. Equiv‐
a‐
lent
to
Undo
the
last
text-
mod‐
i‐
fy‐
ing
com‐
mand.
Undo
all
the
text-
mod‐
i‐
fy‐
ing
com‐
mands
per‐
formed
on
the
line.
Exe‐
cute
the
com‐
mand in
the
input
buf‐
fer.
If
count
is
omit‐
ted,
the
cur‐
rent
line
is
used.
This
exe‐
cutes
an
edi‐
tor
with
the
cur‐
rent
line
as
the
input
"file".
When
you
exit
from
the
edi‐
tor,
the
result
is
exe‐
cuted.
Line
feed
and
print
cur‐
rent
line.
Exe‐
cute
the
cur‐
rent
line,
regard‐
less
of
mode (new‐
line).
Exe‐
cute
the
cur‐
rent
line,
regard‐
less
of
mode (return).
Insert
a at
the
begin‐
ning
of
the
cur‐
rent
line
and
after
each
embed‐
ded
new‐
line,
and
exe‐
cute
the
line.
Use‐
ful
for
insert‐
ing
the
cur‐
rent
com‐
mand
line
in
the
his‐
tory
list
with‐
out
exe‐
cut‐
ing
it.
List
the
file
names
that
match
the
cur‐
rent
word if
an
aster‐
isk
were
appended
to
it.
Search
your
alias
list
for
an
alias
with
the
name (under‐
score
let‐
ter).
If
an
alias
of
this
name
is
defined,
its
value
is
exe‐
cuted
as
a
com‐
mand
sequence
on
the
cur‐
rent
line.
This
pro‐
vides
a
sim‐
ple
macro
capa‐
bil‐
ity.
EXTERNAL
INFLU‐
ENCES
For
infor‐
ma‐
tion
about
the
UNIX
Stan‐
dard
envi‐
ron‐
ment,
see
stan‐
dards(5).
Envi‐
ron‐
ment
Vari‐
ables
deter‐
mines
the
col‐
lat‐
ing
sequence
used
in
eval‐
u‐
at‐
ing
pat‐
tern
match‐
ing
nota‐
tion
for
file
name
gen‐
er‐
a‐
tion.
If
it
is
not
defined
or
is
empty,
it
defaults
to
the
value
of
deter‐
mines
the
clas‐
si‐
fi‐
ca‐
tion
of
char‐
ac‐
ters
as
let‐
ters,
and
the
char‐
ac‐
ters
matched
by
char‐
ac‐
ter
class
expres‐
sions
in
pat‐
tern
match‐
ing
nota‐
tion.
If
it
is
not
defined
or
is
empty,
it
defaults
to
the
value
of
If
is
not
defined
or
is
empty,
it
defaults
to
(see
lang(5)).
If
any
inter‐
na‐
tion‐
al‐
iza‐
tion
vari‐
able
con‐
tains
an
invalid
value,
they
all
default
to
(see
env‐
i‐
ron(5)).
Inter‐
na‐
tional
Code
Set
Sup‐
port
Sin‐
gle-
and
multi‐
byte
char‐
ac‐
ter
code
sets
are
sup‐
ported.
RETURN
VALUE
Errors
detected
by
the
shell,
such
as
syn‐
tax
errors,
cause
the
shell
to
return
a
nonzero
exit
sta‐
tus.
Oth‐
er‐
wise,
the
shell
returns
the
exit
sta‐
tus
of
the
last
com‐
mand
exe‐
cuted.
See
also
the
spe‐
cial
com‐
mand.
If
the
shell
is
being
used
non‐
in‐
ter‐
ac‐
tively,
the
exe‐
cu‐
tion
of
the
shell
file
is
aban‐
doned.
Run‐
time
errors
detected
by
the
shell
are
reported
by
print‐
ing
the
com‐
mand
or
func‐
tion
name
and
the
error
con‐
di‐
tion.
If
the
line
num‐
ber
on
which
the
error
occurred
is
greater
than
one,
the
line
num‐
ber
is
also
printed
in
brack‐
ets
after
the
com‐
mand
or
func‐
tion
name.
WARNINGS
Some
file
descrip‐
tors
are
used
inter‐
nally
by
the
POSIX
shell.
For
HP-
UX
releases
10.10
and
beyond,
file
descrip‐
tors
24
through
30
are
reserved.
HP-
UX
releases
10.00
and
10.01
reserve
descrip‐
tors
54
through
60.
Appli‐
ca‐
tions
using
these
and
fork‐
ing
a
sub‐
shell
should
not
depend
upon
them
sur‐
viv‐
ing
in
the
sub‐
shell
or
its
descen‐
dants.
If
a
com‐
mand
that
is
a
tracked
alias
is
exe‐
cuted,
and
a
com‐
mand
with
the
same
name
is
installed
in
a
direc‐
tory
in
the
search
path
before
the
direc‐
tory
where
the
orig‐
i‐
nal
com‐
mand
was
found,
the
shell
will
con‐
tinue
to
load
and
exe‐
cute
the
orig‐
i‐
nal
com‐
mand.
Use
the
option
of
the
com‐
mand
to
cor‐
rect
this
sit‐
u‐
a‐
tion.
If
you
move
the
cur‐
rent
direc‐
tory
or
one
above
it,
may
not
give
the
cor‐
rect
response.
Use
the
com‐
mand
with
a
full
path
name
to
cor‐
rect
this
sit‐
u‐
a‐
tion.
Some
very
old
shell
scripts
use
a
caret
as
a
syn‐
onym
for
the
pipe
char‐
ac‐
ter
rec‐
og‐
nize
the
caret
as
a
pipe
char‐
ac‐
ter.
If
a
com‐
mand
is
piped
into
a
shell
com‐
mand,
all
vari‐
ables
set
in
the
shell
com‐
mand
are
lost
when
the
com‐
mand
com‐
pletes.
Using
the
built-
in
com‐
mand
within
a
com‐
pound
com‐
mand
will
cause
the
entire
com‐
mand
to
dis‐
ap‐
pear
from
the
his‐
tory
file.
The
dot
spe‐
cial
com‐
mand,
as
in
reads
the
entire
file
before
any
com‐
mands
are
exe‐
cuted.
There‐
fore,
and
com‐
mands
in
the
file
will
not
apply
to
any
func‐
tions
defined
in
the
file.
Traps
are
not
pro‐
cessed
while
the
shell
is
wait‐
ing
for
a
fore‐
ground
job.
Thus,
a
trap
on
is
not
exe‐
cuted
until
the
fore‐
ground
job
ter‐
mi‐
nates.
The
spe‐
cial
com‐
mand
does
not
han‐
dle
arrays
prop‐
erly.
Only
the
first
ele‐
ment
of
an
array
is
exported
to
the
envi‐
ron‐
ment.
Back‐
ground
pro‐
cesses
started
from
a
non‐
in‐
ter‐
ac‐
tive
shell
can‐
not
be
accessed
with
job
con‐
trol
com‐
mands.
The
value
of
the
vari‐
able
in
the
user's
envi‐
ron‐
ment
affects
the
behav‐
ior
of
scripts.
Col‐
lat‐
ing
Order
In
an
inter‐
na‐
tional
envi‐
ron‐
ment,
char‐
ac‐
ter
order‐
ing
is
deter‐
mined
by
the
value
of
rather
than
by
the
binary
order‐
ing
of
char‐
ac‐
ter
val‐
ues
in
the
machine
col‐
lat‐
ing
sequence.
This
brings
with
it
cer‐
tain
atten‐
dant
dan‐
gers,
par‐
tic‐
u‐
larly
when
using
range
expres‐
sions
in
file
name
gen‐
er‐
a‐
tion
pat‐
terns.
For
exam‐
ple,
the
com‐
mand,
might
be
expected
to
match
all
file
names
begin‐
ning
with
a
low‐
er‐
case
alpha‐
betic
char‐
ac‐
ter.
How‐
ever,
if
dic‐
tio‐
nary
order‐
ing
is
spec‐
i‐
fied
by
it
would
also
match
file
names
begin‐
ning
with
an
upper‐
case
char‐
ac‐
ter
(as
well
as
those
begin‐
ning
with
accented
let‐
ters).
Con‐
versely,
it
would
fail
to
match
let‐
ters
col‐
lated
after
in
lan‐
guages
such
as
Dan‐
ish
or
Nor‐
we‐
gian.
The
cor‐
rect
(and
safe)
way
to
match
spe‐
cific
char‐
ac‐
ter
classes
in
an
inter‐
na‐
tional
envi‐
ron‐
ment
is
to
use
a
pat‐
tern
(see
reg‐
exp(5))
of
the
form:
This
uses
to
deter‐
mine
char‐
ac‐
ter
classes
and
works
pre‐
dictably
for
all
sup‐
ported
lan‐
guages
and
code‐
sets.
For
shell
scripts
pro‐
duced
on
non‐
in‐
ter‐
na‐
tion‐
al‐
ized
sys‐
tems
(or
with‐
out
con‐
sid‐
er‐
a‐
tion
for
the
above
dan‐
gers),
it
is
rec‐
om‐
mended
that
they
be
exe‐
cuted
in
a
non-
NLS
envi‐
ron‐
ment.
This
requires
that
and
so
on,
be
set
to
or
not
set
at
all.
His‐
tory
File
and
Locales
The
his‐
tory
file
does
not
sup‐
port
mix‐
ing
of
locales
in
the
same
file.
For
users
of
mul‐
ti‐
ple
locales,
you
can
assign
a
unique
his‐
tory
file
for
each
locale
by
set‐
ting
as:
On
encoun‐
ter‐
ing
a
his‐
tory
file
with
invalid
char‐
ac‐
ters
for
the
cur‐
rent
locale
set‐
ting,
the
shell
will
inform
the
user
about
it
and
con‐
tinue
pro‐
cess‐
ing
user
input.
No
his‐
tory
fea‐
tures
will
be
avail‐
able
to
the
user
in
such
a
ses‐
sion.
Restart‐
ing
the
shell
after
set‐
ting
a
new
his‐
tory
file
or
after
remov‐
ing
the
cur‐
rent
his‐
tory
file
allows
the
user
to
access
the
his‐
tory
fea‐
tures.
Here-
Doc‐
u‐
ment
Temp
Files
The
con‐
tents
of
here-
doc‐
u‐
ments
are
stored
in
tem‐
po‐
rary
files
named
Usu‐
ally,
these
tem‐
po‐
rary
files
are
removed
after
they
are
used.
How‐
ever,
due
to
design
lim‐
i‐
ta‐
tions,
these
tem‐
po‐
rary
files
may
some‐
times
con‐
tinue
to
exist
after
the
shell
exits.
pid
is
the
process
ID
of
the
shell.
num‐
ber
is
a
sequence
num‐
ber
for
the
here-
doc‐
u‐
ment
files.
AUTHOR
was
devel‐
oped
by
AT&T,
OSF,
and
HP.
FILES
Read
to
set
up
user's
cus‐
tom
envi‐
ron‐
ment
To
find
home
direc‐
to‐
ries
Read
to
set
up
sys‐
tem
envi‐
ron‐
ment
Secu‐
rity
pro‐
file
Archived
exe‐
cutable,
espe‐
cially
for
root
access
For
here-
doc‐
u‐
ments
if is
not
acces‐
si‐
ble
Stan‐
dard
exe‐
cutable
for
the
POSIX
shell
For
here-
doc‐
u‐
ments
if is
acces‐
si‐
ble
SEE ALSOcat(1),
cd(1),
com‐
mand(1),
echo(1),
ed(1),
env(1),
getopts(1),
kill(1),
ln(1),
login(1),
new‐
grp(1),
printf(1),
pwd(1),
read(1),
stty(1),
test(1),
time(1),
umask(1),
vi(1),
dup(2),
exec(2),
fork(2),
pipe(2),
stty(2),
ulimit(2),
umask(2),
wait(2),
rand(3C),
a.out(4),
pro‐
file(4),
env‐
i‐
ron(5),
lang(5),
reg‐
exp(5),
sig‐
nal(5),
stan‐
dards(5).
STAN‐
DARDS
CON‐
FOR‐
MANCE
sh-posix(1)