sh-posix(1) General Commands Manual sh-posix(1)
sh-posix: sh, rsh - standard and restricted POSIX.2-conformant command shells
option]... string] [arg]...
option]... string] [arg]...
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
is a command programming language that executes commands read from a terminal or a file.
is a restricted version of See the subsection below.
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 environment 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. Commands 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).
The following options are interpreted by the shell when it is invoked.
Read commands from
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.
is used to set up login names and execution environments where capabilities are more controlled than those of the standard shell. The
actions of are identical to those of except that the following are forbidden:
o Changing directory (see the special command and cd(1))
o Setting the value of or
o Specifying path or command names containing
o Redirecting output and
The restrictions above are enforced after the and files are interpreted.
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 proce-
dures 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 directory.
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 directory).
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.
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 separate 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
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 that is known outside the local shell, usually by means of the special command.
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 compound 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
normally, 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 optionally 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 pipeline 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 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 using the option of the special commands and
list following it to be executed only if the preceding pipeline returns a zero value.
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.
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 command 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 param-
eter 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, execute the list (if any). If no list or list is executed, returns a zero
Print the set of words on standard error (file descriptor 2), each preceded by a number. If word ... is omitted, print the posi-
tional 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, terminate 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 expression is true. See the subsection for a description of expression.
Note that and are keywords and require blanks between them and expression.
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 location and the exit status, when there are no syntax errors, is zero.
Commands that are marked with "%" are treated specially in the following 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 containing file. If any arguments arg are given, they become the positional parame-
ters. Otherwise, the positional parameters are unchanged. The exit status is the exit status of the last command 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 environment variables are set to the new current directory and the former
With (default), preserve logical naming when treating symbolic links. moves the current directory one path component closer to the
With preserve the physical path when treating symbolic links. changes the working directory to the actual parent directory of the
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. Otherwise, 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
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 resulting commands. Allows parameter substitution for keywords and charac-
ters that would otherwise be unrecognized in the resulting commands.
Parameter assignments remain in effect after the command completes. 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 executed. 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 environment 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 commands.
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 pre-
vious 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 command 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 letters
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 argument 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
Affect the way the current shell environment remembers the locations of utilities. With utility, add utility locations to a list of
remembered locations. With no arguments, print the contents of the list. With forget all previously remembered utility locations.
List information about each given job, or all active jobs if job is not specified. With list process IDs in addition to the normal
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 (termi-
nate) 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 evaluation.
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
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 command,
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 terminal 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 status
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.
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
The options are defined as follows.
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.
from truncating existing regular files. Requires to truncate a file when turned on.
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 read-
Disable file name generation.
Specify that each command whose name is an
identifier becomes a tracked alias when first encountered.
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 execute them.
The option is ignored for interactive shells.
Set an option argument from the following list. Repeat the option to specify additional option arguments.
Run all background jobs at a lower priority.
Use a inline editor for command entry.
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.
Append a trailing
to all directory names resulting from file name generation.
Do not save function definitions in history file.
Use a inline editor for command entry.
Process each character as it is typed in
mode (always on).
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
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.
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 nonnega-
tive 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 integers. 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 number 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 function, create a new instance of the parameter name. The parameter 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; otherwise, it is determined by the width of the value of first assign-
ment. 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 state-
ment. 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 environment). Flagged as
Parameter is an integer.
This makes arithmetic faster. If n is nonzero it defines the output arithmetic base; otherwise, the first assignment deter-
mines 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 subsequent 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 subsequently 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 incompatible
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 cur-
rent 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 processes
(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 definitions from the current shell execution environment. See also the spe-
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 special 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. With-
out job, wait for all currently active child processes to terminate and returns with a zero exit status. See the subsection 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 function, or a reserved word.
A beginning with causes that word and all the following characters up to a newline to be ignored.
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 char-
acters excluding metacharacters, quoting characters, file expansion characters, 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 subsection. 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 executed. 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 redefined:
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 parameter and respectively. In addition, tilde substitution is attempted
when the value of a parameter assignment begins with a
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
characters before the command is executed. See the subsection. The command substitution can be replaced by the equivalent but faster Com-
mand substitution of most special commands that do not perform input/output redirection are carried out without creating a separate
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.
A is an identifier, one or more decimal digits, or one of the characters 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 element 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 without 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 substitution.
Substitute the value of the parameter, if any.
Braces are required when parameter is followed by a letter, digit, or underscore that should not be interpreted as part of
its name or when a named parameter is subscripted. 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 character).
See the subsection.
If an array parameter with subscript or is used, the value for each element is substituted (separated by a field separator
If parameter is or the number of positional parameters is substituted. Otherwise, the length of the value of the parameter is
Substitute the number of elements in the array.
If parameter is set and is nonnull, substitute 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, substitute 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, substitute 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 substituted. In the former case, the smallest match-
ing 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; other-
wise, substitute the value of parameter. In the former, the smallest matching pattern is deleted; in the latter, 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.
o The following parameters are set automatically 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, separated 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
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 matching 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 debugging purposes.
The line number of the current line within the script or
function being executed.
The previous working directory set by the
The value of the last option argument processed by the
If set to 0, will suppress error messages from the special command. is initially set to 1.
The index of the last option argument processed by the
The process number of the parent of the shell.
The present working directory set by the
Each time this parameter is evaluated, a random integer,
uniformly distributed between 0 and 32767, is generated. The sequence of random numbers can be initialized 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
reference is the value that was assigned plus the number of seconds since the assignment.
o The following parameters are used by the shell:
The search path for the
command, a list of directories 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 executed for interactive shells only. Under the environment (see standards(5)), this file is executed
for both interactive and non-interactive shells.
The default editor name for the
The search path for function definitions,
a list of directories separated by colons. This path is searched when a function with the attribute is referenced 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 subsection 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
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 separate arguments for the
substitution (see the subsection). If the value of is space, tab, and newline, or if is unset and it is being used to sepa-
rate the results of command or parameter substitution, 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 environ(5).
The collating sequence to use when sorting names and
when character ranges occur in patterns. See environ(5).
The character classification information to use.
Changing the value of after the shell has started does not affect the lexical processing of shell commands in the current
shell execution environment or its subshells. See environ(5).
The shell uses to detect nonprintable characters in the input and tries to handle 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
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 format.
The numeric format.
The date and time format.
If this variable is set,
the value is used to determine the column length for printing lists. lists print vertically until about two-thirds of lines
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 seconds. 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 message to be printed, in which case the message will undergo
parameter and command 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 separated 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 completion.
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 automatically by the shell (although and are set by see
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 result-
ing from parameters 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 disabled with the
special command. The form of the patterns is the defined in regexp(5). The word is replaced with sorted file names matching the pattern.
If no file name is found that matches the pattern, 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 following:
Matches any one of the given patterns.
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.
Each of the metacharacters (see the subsection) 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 backslash The pair is ignored; the current and following lines are concatenated.
All characters enclosed between a pair of apostrophes are quoted. An apostrophe cannot appear within apostrophes.
Parameter and command substitution occurs inside quotation marks (...). quotes the characters , and
Inside grave accent marks quotes the characters 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 assignment value or as a file name. However, when used as a
command argument, is equivalent 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 spe-
cial command names cannot be altered by quoting them.
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 representing the arithmetic base and n is a number in that base. If is
omitted, base 10 is used.
An arithmetic expression uses the same syntax, precedence, and associativity of expression as the C language. All the integral operators,
other than and are supported. Variables can be referenced by name within an arithmetic expression without using the parameter substitution
syntax. When a variable is referenced, its value is evaluated as an arithmetic expression.
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 expression. More precisely, is equivalent to ....
Arithmetic expressions given with command, and will be processed according to ISOC standard with the exception of and operators.
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.
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 special 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 special 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 associated with a terminal 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 permission 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 characters.
True, if string1 comes after string2 based on the ASCII value of their characters.
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.
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 command. 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 performed.
Use file word as standard input (file descriptor
Use file word as standard output (file descriptor If the file does not exist, it is created. If the file exists, and the
option is on, an error occurs; otherwise, 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 overrides the option.
Use file word as standard output. If the file exists, output is appended to it (by first searching for the end-of-file); oth-
erwise, 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 parameter substitution, command substitution or file name generation 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 characters of the document. Otherwise,
parameter and command substitution occurs, is ignored, and must be used to quote the characters and the first charac-
ter of word.
If is appended to all leading tabs are stripped from word and from the document.
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 preceded 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,
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
By using the redirection operators above, the input and output of a coprocess may be moved to a numbered file descriptor, allowing other
commands to write to them and read from them. If the input of the current coprocess is moved to a numbered file descriptor, another copro-
cess 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 envi-
ronment for the execution of a command contains the file descriptors of the invoking shell as modified by input/output specifications.
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 iden-
tifiers 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 envi-
ronment. If the user modifies the values of these parameters or creates new ones by using the or special commands, the values become part
of the environment. 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, 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 assignment arguments are placed in the environment, 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 disappear someday.
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 commands, with the arguments passed as positional parameters. (See the
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 function. 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 without reinvoking the shell. Functions that must be defined across separate invocations of the shell should be
placed in the file.
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
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 command, running other commands, and eventually 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. Background jobs normally are allowed to produce output, but
can be disabled with the command. 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 job with the given number.
Any job whose command line begins with
Any job whose command line contains
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 background job that completes triggers any trap set for
If you try to exit from shell while jobs are stopped, you are warned with the message 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 terminated.
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).
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).
Substitutions are made each time a command is executed. checks the command name to determine whether it matches a special command. 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 positional parame-
ters, then sets them to the arguments of the function call. The positional 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 sys-
tem 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 specified 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 per-
missions 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 inter-
preter. If the first two characters of the script file are expects an interpreter path name to follow. then attempts to execute the spec-
ified interpreter 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 command is also executed in a subshell without removing nonexported quantities.
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 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 an argu-
ment 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 execution. 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 kilobytes.
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 com-
mands will be available in the history file.
Command Line Editing
Normally, each command line typed at a terminal 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
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
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 provide 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 characters is caret followed by a character. For example, is the nota-
tion 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 followed by a character. For example, (pronounced 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). Neither 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, 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.
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 character. The erase character is user-definable with the command; it is usually set to The system
Delete current character.
eof Terminate the shell if the current line is null. The eof character is user-definable with the command; it is usually
set to The system 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 current character with next character. In mode, transpose two previous characters.
Capitalize current character.
Capitalize current word.
Change the current word to lowercase.
Delete from the cursor to the end of the line.
If preceded by a numerical parameter whose value is less that the current cursor position, then delete from the given
position up to the cursor. If preceded by a numerical parameter whose value is greater than the current cursor posi-
tion, 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 current line. If two kill characters are entered in succession, all subsequent consecutive kill
characters cause a line feed (useful when using paper terminals). The kill character is user-definable with the com-
mand; it is usually 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
Execute the current line
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) history line.
Fetch the most recent (youngest) history line.
Reverse search history for a previous command line containing
string. If a parameter of zero is given, the search is forward. string is terminated 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 con-
taining the most recent string is accessed. In this case, a parameter of zero reverses the direction of the search.
Execute the current line
and fetch the next line relative to current 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 command 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
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 directory.
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 characters 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 history 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 cursor 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 processing is initially enabled and the command is echoed again if the speed is 1200 baud or greater and
contains any control characters, or if less than one second has elapsed since the prompt was printed. The escape (ESC) character termi-
nates 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 canonical processing on the terminal. This mode is implicit for systems that do not support two alter-
nate 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 character.
eof Terminate the shell if the current line is null. The eof character is user-definable with the command; it is usually
set to The system 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 character.
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 character.
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,
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 command in the history list is accessed.
Fetch next command.
Each time is entered, the next later command in the history list is accessed.
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
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.
Move cursor forward to the character position specified by
motion, deleting all characters between the original cursor position and the new position, and enter insert mode. If
motion is the entire line is deleted.
Delete from the current character through the end of line
and enter insert mode. Equivalent to
Move cursor to the character position specified by
motion, deleting all characters between the original cursor position and the new position. If motion is the entire
line will be deleted.
Delete from the current character through the end of line.
Enter insert mode before the current character.
Enter insert mode before the beginning of the line.
Equivalent to the two-character sequence
Insert the previous text modification before the cursor.
Insert the previous text modification after the cursor.
Enter insert mode and replace characters on the screen
with characters you type, overlay fashion.
Replace the current character with
Delete the current character.
Delete the preceding character.
Repeat the previous text modification command.
Invert the case of the current character and advance the cursor.
Append the count word of the previous command at the current cursor location and enter insert mode at the end of the appended
text. The last word is used if count is omitted.
Append an to the current word and attempt file name generation. If no match is found, ring the bell. If a match is found,
replace the word with the matching string of file names and enter insert mode.
Attempt file name completion on the current word.
Replace 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, append a if the file is a directory or append a space if the file is not a direc-
Yank current character through character that
motion would move the cursor to and put them into the delete buffer. The text and cursor are unchanged.
Yank from current position to end of line.
Undo the last text-modifying command.
Undo all the text-modifying commands performed on the line.
Execute the command
in the input buffer. If count is omitted, the current line is used. This executes an editor with the current line
as the input "file". When you exit from the editor, the result is executed.
Line feed and print current line.
Execute the current line, regardless of mode
Execute the current line, regardless of mode
Insert a at the beginning of the current line and after each embedded newline, and execute the line. Useful for inserting the
current command line in the history list without executing it.
List the file names that match the current word
if an asterisk were appended to it.
Search your alias list for an alias with the name
(underscore letter). If an alias of this name is defined, its value is executed as a command sequence on the current
line. This provides a simple macro capability.
For information about the UNIX Standard environment, see standards(5).
determines the collating sequence used in evaluating pattern matching notation for file name generation. If it is not defined or is empty,
it defaults to the value of
determines the classification of characters as letters, and the characters matched by character class expressions in pattern matching 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 internationalization variable contains an invalid value, they all default to (see environ(5)).
International Code Set Support
Single- and multibyte character code sets are supported.
Errors detected by the shell, such as syntax errors, cause the shell to return a nonzero exit status. Otherwise, the shell returns the
exit status of the last command executed. See also the special command.
If the shell is being used noninteractively, the 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 on which the error occurred is greater than
one, the line number is also printed in brackets after the command or function name.
Some file descriptors are used internally by the POSIX shell. For HP-UX releases 10.10 and beyond, file descriptors 24 through 30 are
reserved. HP-UX releases 10.00 and 10.01 reserve descriptors 54 through 60. Applications using these and forking a subshell should not
depend upon them surviving in the subshell or its descendants.
If a command that is a tracked alias is executed, and 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 load and execute the original command. Use the option of
the command to correct this situation.
If you move the current directory or one above it, may not give the correct response. Use the command with a full path name to correct
Some very old shell scripts use a caret as a synonym for the pipe character recognize the caret as a pipe character.
If a command is piped into a shell command, all variables set in the shell command are lost when the command completes.
Using the built-in command within a compound command will cause the entire command to disappear from the history file.
The dot special command, as in reads the entire file before any commands are executed. Therefore, and commands in the file will not apply
to any functions defined in the file.
Traps are not processed while the shell is waiting for a foreground job. Thus, a trap on is not executed until the foreground job termi-
The special command does not handle arrays properly. Only the first element of an array is exported to the environment.
Background processes started from a noninteractive shell cannot be accessed with job control commands.
The value of the variable in the user's environment affects the behavior of scripts.
In an international environment, character ordering is determined by the value of rather than by the binary ordering of character values in
the machine collating sequence. This brings with it certain attendant dangers, particularly when using range expressions in file name gen-
eration patterns. For example, the command,
might be expected to match all file names beginning with a lowercase alphabetic character. However, if dictionary ordering is specified by
it would also match file names beginning with an uppercase character (as well as those beginning with accented letters). Conversely, it
would fail to match letters collated after in languages such as Danish or Norwegian.
The correct (and safe) way to match specific character classes in an international environment is to use a pattern (see regexp(5)) of the
This uses to determine character classes and works predictably for all supported languages and codesets. For shell scripts produced on
noninternationalized systems (or without consideration for the above dangers), it is recommended that they be executed in a non-NLS envi-
ronment. This requires that and so on, be set to or not set at all.
History File and Locales
The history file does not support mixing of locales in the same file. For users of multiple locales, you can assign a unique history file
for each locale by setting as:
On encountering a history file with invalid characters for the current locale setting, the shell will inform the user about it and continue
processing user input. No history features will be available to the user in such a session. Restarting the shell after setting a new his-
tory file or after removing the current history file allows the user to access the history features.
Here-Document Temp Files
The contents of here-documents are stored in temporary files named Usually, these temporary files are removed after they are used. How-
ever, due to design limitations, these temporary files may sometimes continue to exist after the shell exits. pid is the process ID of the
shell. number is a sequence number for the here-document files.
was developed by AT&T, OSF, and HP.
Read to set up user's custom environment
To find home directories
Read to set up system environment
Archived executable, especially for root access
For here-documents if is not accessible
Standard executable for the POSIX shell
For here-documents if is accessible
cat(1), cd(1), command(1), echo(1), ed(1), env(1), getopts(1), kill(1), ln(1), login(1), newgrp(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), environ(5), lang(5), regexp(5), signal(5), standards(5).