 |
» |
|
|
 |
NAMEsh-posix: sh, rsh — standard and restricted POSIX.2-conformant command shells SYNOPSISsh
[±aefhikmnprstuvx]
[±o
option]...
[-c
string]
[arg]... rsh
[±aefhikmnprstuvx]
[±o
option]...
[-c
string]
[arg]... RemarksThis shell is intended to conform to the shell specification of the POSIX.2
Shell and Utility
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 DESCRIPTIONDESCRIPTIONsh
is a command programming language
that executes commands read from a terminal or a file. rsh
is a restricted version of
sh.
See the
rsh Restrictions
subsection below. Shell InvocationIf the shell is invoked by an
exec*()
system call and the first character of argument zero
(shell parameter
0)
is dash
(-),
the shell is assumed to be a login shell
and commands are read first from
/etc/profile,
then from either
.profile
in the current directory or
$HOME/.profile
if either file exists,
and finally from the file named
by performing parameter substitution on
the value of the environment parameter
ENV,
if the file exists.
If the
-s
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
sh
with
arg,
the script
arg
must have read permission and any
setuid
and
setgid
settings will be ignored.
Commands are read as described below. Shell output, except for the output of some of the commands
listed in the
Special Commands
subsection, is written to standard error (file descriptor 2). OptionsThe following options are interpreted by the shell when it is invoked.
- -c string
Read commands from
string. - -i
If
-i
is present or if the shell input and output
are attached to a terminal (as reported by
tty()),
the shell is interactive.
In this case
SIGTERM
is ignored and
SIGINT
is caught and ignored (so that
wait
is interruptible).
In all cases,
SIGQUIT
is ignored by the shell.
See
signal(5). - -r
The shell is a restricted shell. - -s
If
-s
is present or if no arguments remain,
commands are read from the standard input.
The remaining options and operands are described under the
set
command in the
Special Commands
subsection. rsh Restrictionsrsh
is used to set up login names and execution environments
where capabilities are more controlled than those of the standard shell.
The actions of
rsh
are identical to those of
sh,
except that the following are forbidden:
Changing directory (see the
cd
special command and
cd(1)) Setting the value of
SHELL,
ENV,
or
PATH Specifying path or command names containing
/ Redirecting output
(>,
>|,
<>,
and
>>)
The restrictions above are enforced after the
.profile
and
ENV
files are interpreted. When a command to be executed is found to be a shell procedure,
rsh
invokes
sh
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 directory. These rules effectively give the writer of the
.profile
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
/usr/rbin)
that can be safely invoked by
rsh.
HP-UX systems provide a restricted editor
red
(see
ed(1)),
suitable for restricted users. Definitions- metacharacter
One of the following characters: ; & ( ) | < > newline space tab - blank
A tab or a space. - identifier
A sequence of letters, digits, or underscores
starting with a letter or underscore.
Identifiers are used as names for
functions
and
named parameters. - word
A sequence of
characters
separated by one or more nonquoted
metacharacters. - command
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. - special command
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. - parameter
An
identifier,
a decimal number,
or one of the characters
!,
#,
$,
*,
-,
?,
@,
and
_.
See the
Parameter Substitution
subsection. - named parameter
A
parameter
that can be assigned a value.
See the
Parameter Substitution
subsection. - variable
A
parameter. - environment variable
A
parameter
that is known outside the local shell,
usually by means of the
export
special command.
CommandsA 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. Simple CommandsA simple command is a sequence of blank-separated words
that may be preceded by a parameter assignment list.
(See the
Environment
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
0
(see
exec(2)).
The
value
of a simple command is its exit status
if it terminates normally, or
128+errorstatus
if it terminates abnormally (see
signal(5)
for a list of
errorstatus
values). A
pipeline
is a sequence of one or more commands separated by a bar
(|)
and optionally preceded by an exclamation mark
(!).
The standard output of each command 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
-p
option of the special commands
read
and
print. - &&
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 CommandsUnless 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:
! } elif for then
[[ case else function time
]] do esac if until
{ done fi select while A compound command is one of the following. case word
in [[;] [(] pattern [| pattern]...) list
;;]... ; esac
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
File Name Generation
subsection).
The
;;
case terminator cannot be replaced by newlines.
for identifier [in word ...] ; do list ; done
Set
identifier
to each
word
in sequence
and execute the
do
list.
If
in
word ...
is omitted, set
identifier
to each set positional parameter instead.
See the
Parameter Substitution
subsection.
Execution ends when there are no more positional parameters
or words in the list.
function identifier { list ; }
identifier () { 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
Functions
subsection.
if list ; then list ; [elif list ; then list ;]... [else list ;] fi
Execute the
if
list
and, if its exit status is zero,
execute the first
then
list.
Otherwise, execute the
elif
list
(if any) and, if its exit status is zero,
execute the next
then
list.
Failing that, execute the
else
list
(if any).
If no
else
list
or
then
list
is executed,
if
returns a zero exit status.
select identifier [in word ...] ; do list ; done
Print the set of
words
on standard error (file descriptor 2),
each preceded by a number.
If
in
word ...
is omitted,
print the positional parameters instead
(see the
Parameter Substitution
subsection).
Print the
PS3
prompt and read a line from standard input into the parameter
REPLY.
If this line consists of the number of one of the listed
words,
set
identifier
to the corresponding
word,
execute
list,
and repeat the
PS3
prompt.
If the line is empty, print the selection list again,
and repeat the
PS3
prompt.
Otherwise, set
identifier
to null, execute
list,
and repeat the
PS3
prompt.
The select loop repeats until a
break
special command or end-of-file is encountered.
time pipeline
Execute the
pipeline
and print the elapsed time,
the user time,
and the system time on standard error.
Note that the
time
keyword can appear anywhere in the
pipeline
to time the entire
pipeline.
To time a particular
command in a
pipeline,
see
time(1).
until list ; do list ; done
Execute the
until
list.
If the exit status of the last command in the list is nonzero,
execute the
do
list
and execute the
until
list
again.
When the exit status of the last command in the
until
list
is zero, terminate the loop.
If no commands in the
do
list
are executed,
until
returns a zero exit status.
while list ; do list ; done
Execute the
while
list.
If the exit status of the last command in the list is zero,
execute the
do
list
and execute the
while
list
again.
When the exit status of the last command in the
while
list
is nonzero, terminate the loop.
If no commands in the
do
list
are executed,
while
returns a nonzero exit status.
( list )
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.
{ list ; }
Execute
list,
but not in a separate environment.
Note that
{
is a keyword and requires a trailing blank to be recognized.
[[ expression ]]
Evaluate
expression
and return a zero exit status when
expression
is true.
See the
Conditional Expressions
subsection for a description of
expression.
Note that
[[
and
]]
are keywords and require blanks between them and
expression.
Special CommandsSpecial commands are simple commands that are executed in the shell process.
They permit input/output redirection.
Unless otherwise indicated, 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. %
: [arg]...
(colon)
Only expand parameters.
A zero exit status is returned.
%
. file [arg]...
(period)
Read and execute commands from
file
and return.
The commands are executed in the current shell environment.
The search path specified by
PATH
is used to find the directory containing
file.
If any arguments
arg
are given, they become the positional parameters.
Otherwise, the positional parameters are unchanged.
The exit status is the exit status of the last command executed.
&
alias [-tx] [name[=value]]...
With
name=value
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
name=value
omitted, print the list of aliases in the form
name=value
on standard output. With
name
specified without
=value,
print the specified alias. With
-t,
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
PATH
is reset, but the alias remains tracked.
With
name=value
omitted, print the list of tracked aliases in the form
name=pathname
on standard output. With
-x,
set exported aliases.
An exported alias is defined across subshell environments.
With
name=value
omitted, print the list of exported aliases in the form
name=value
on standard output. Alias returns true unless a
name
is given for which no alias has been defined. See also the
unalias
special command.
bg [job]...
Put the specified
jobs
into the background.
The current job is put in the background if
job
is unspecified.
See the
Jobs
subsection for a description of the format of
job.
See also the
fg
special command.
%
break [n]
Exit from the enclosing
for,
select,
until,
or
while
loop, if any.
If
n
is specified, exit from
n
levels.
cd [-L|-P] [arg]
cd old new
In the first form, change the current working directory
(PWD)
to
arg.
If
arg
is
-,
the directory is changed to the previous directory
(OLDPWD).
The shell parameter
HOME
is the default
arg.
After the
cd,
the
PWD
and
OLDPWD
environment variables are set to the new current directory
and the former directory respectively. With
-L
(default), preserve logical naming when treating symbolic links.
cd -L ..
moves the current directory one path component closer
to the root directory. With
-P,
preserve the physical path when treating symbolic links.
cd -P ..
changes the working directory to the actual parent directory
of the current directory. The shell parameter
CDPATH
defines the search path for
the directory containing
arg.
Alternative directory names are separated by
a colon
(:).
If
CDPATH
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
cd
substitutes the string
new
for the string
old
in the current directory name,
PWD,
and tries to change to this new directory.
command [arg]...
Treat
arg
as a command, but disable function lookup on
arg.
See
command(1)
for usage and description.
%
continue [n]
Resume the next iteration of the enclosing
for,
select,
until,
or
while
loop.
If
n
is specified, resume at the
nth
enclosing loop.
echo [arg]...
Print
arg
on standard output.
See
echo(1)
for usage and description.
See also the
print
special command.
%
eval [arg]...
Read the arguments as input to the shell and execute the resulting commands.
Allows parameter substitution for keywords and characters
that would otherwise be unrecognized in the resulting commands.
%
exec [arg]...
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 [n]
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
ignoreeof
option set.
(See the
set
special command.)
%& export [name[=value]]...
%& export -p
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
-p,
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.
fc [-r] [-e ename] [first [last]]
fc -l [-nr] [first [last]]
fc -s [old=new] [first]
fc -e - [old=new] [command]
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
HISTSIZE
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
-l,
list the commands on standard output.
Without
-l,
invoke the editor program
ename
on a file containing these keyboard commands.
If
ename
is not supplied, the value of the parameter
FCEDIT
(default
/usr/bin/ed)
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
-r,
reverse the order of the commands. With
-n,
suppress command numbers when listing. With
-s,
reexecute the command without invoking an editor. The
old=new
argument replaces the first occurrence of string
old
in the command to be reexecuted by the string
new.
fg [job]...
Bring each
job
into the foreground in the order specified.
If no
job
is specified, bring the current job into the foreground.
See the
Jobs
subsection for a description of the format of
job.
See also the
bg
special command.
getopts optstring name [arg]...
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
getopts
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
-letter,
name
is set to
letter.
For an option specified as
+letter,
name
is set to
+letter.
The index of the next
arg
is stored in
OPTIND.
The option argument, if any, is stored in
OPTARG.
If no option argument is found,
or the option found does not take an argument,
OPTARG
is unset. A leading
:
in
optstring
causes
getopts
to store the letter of an invalid option in
OPTARG,
and to set
name
to
?
for an unknown option and to
:
when a required option argument is missing.
Otherwise,
getopts
prints an error message.
The exit status is nonzero when there are no more options.
& hash [utility]...
& hash -r
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
-r,
forget all previously remembered utility locations.
jobs [-lnp] [job]...
List information about each given job,
or all active jobs if
job
is not specified.
With
-l,
list process IDs in addition to the normal information.
With
-n,
display only jobs that have stopped or exited since last notified.
With
-p,
list only the process group.
See the
Jobs
subsection for a description of the format of
job.
kill [-s signal] process ...
kill -l
kill [-signal] process ...
Send either signal 15 (SIGTERM,
terminate) or the specified
signal
to the specified jobs or processes.
If the signal being sent is
TERM
(terminate) or
HUP
(hangup),
the job or process is sent a
CONT
(continue) signal when stopped.
See
kill(1)
for usage and description. With
-l,
list the signal names and numbers.
Evaluate each
arg
as a separate arithmetic expression.
See the
Arithmetic Evaluation
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.
%
newgrp [-] [group]
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
.profile
and
$ENV
files.
See
newgrp(1)
for usage and description.
Equivalent to
exec newgrp arg ....
print [-nprRsu[n]] [arg]...
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
-n,
do not add a newline character to the output. With
-p,
write the arguments onto the pipe of the process spawned with
|&
instead of standard output. With
-R
or
-r
(raw mode),
ignore the escape conventions of
echo.
With
-R,
print all subsequent arguments and options other than
-n. With
-s,
write the arguments into the history file instead of to standard output. With
-u,
specify a one-digit file descriptor unit number
n
on which the output will be placed.
The default is
1
(standard output).
pwd [-L|-P]
Print the name of the current working directory (equivalent to
print -r - $PWD).
With
-L
(the default),
preserve the logical meaning of the current directory.
With
-P,
preserve the physical meaning of the current directory if it is a
symbolic link.
See also the
cd
special command,
cd(1),
ln(1),
and
pwd(1).
read [-prsu[n]] [name?prompt] [name]...
The shell input mechanism.
Read one line (by default, from standard input)
and break it up into words using the characters in
IFS
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
0,
unless an end-of-file is encountered. With
-p,
take the input line from the input pipe
of a process spawned by the shell using
|&.
An end-of-file with
-p
causes cleanup for this process
so that another process can be spawned. With
-r
(raw mode), a
\
at the end of a line does not signify line continuation. With
-s,
save the input as a command in the history file. With
-u,
specify a one-digit file descriptor unit to read from.
The file descriptor can be opened with the
exec
special command.
The default value of
n
is
0
(standard input).
If
name
is omitted,
REPLY
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).
%& readonly [name[=value]]...
%& readonly -p
Mark the given
names
read only.
These names cannot be changed by subsequent assignment. With
-p,
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.
%
return [n]
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
return
is invoked while not in a function or a
.
script (see the
.
special command), it has the same effect as an
exit
command. %
set
[{-|+}abCefhkmnopstuvx]
[{-|+}o
option]...
[{-|+}A
name] [arg]... Set
(-)
or clear
(+)
execution options
or perform array assignments
(-A, +A).
All options except
-A
and
+A
can be supplied in a shell invocation
(see the
SYNOPSIS
section and the
Shell Invocation
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
echo $-. The
-
and
+
options can be intermixed in the same command,
except that there can be only one
-A
or
+A
option. Unless
-A
or
+A
is specified, the remaining
arg
arguments are assigned consecutively to the positional parameters
1,
2, .... The
set
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.
- -A
Array assignment.
Unset the variable
name
and assign values sequentially from the list
arg.
With
+A,
do not unset the variable
name
first. - -a
Automatically export subsequently defined parameters. - -b
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. - -C
Prevent redirection
>
from truncating existing files.
Requires
>|
to truncate a file when turned on. - -e
Execute the
ERR
trap, if set, and exit
if
a command has a nonzero exit status,
and is not part of the compound list following a
if,
until,
or
while
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. - -f
Disable file name generation. - -h
Specify that each command whose name is an
identifier
becomes a tracked alias when first encountered. - -k
Place all parameter assignment arguments
(not just those that precede the command name)
into the environment for a command. - -m
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. - -n
Read commands and check them for syntax errors, but do not execute them.
The
-n
option is ignored for interactive shells. - -o
Set an
option
argument from the following list.
Repeat the
-o
option to specify additional
option
arguments.
- allexport
Same as
-a. - bgnice
Run all background jobs at a lower priority. - emacs
Use a
emacs-style
inline editor for command entry. - errexit
Same as
-e. - gmacs
Use a
gmacs-style
inline editor for command entry. - ignoreeof
Do not exit from the shell on end-of-file
(eof,
as defined by
stty;
default is
^D).
The
exit
special command must be used. - keyword
Same as
-k. - markdirs
Append a trailing
/
to all directory names resulting from file name generation. - monitor
Same as
-m. - noclobber
Same as
-C. - noexec
Same as
-n. - noglob
Same as
-f. - nolog
Do not save function definitions in history file. - notify
Same as
-b. - nounset
Same as
-u. - privileged
Same as
-p. - trackall
Same as
-h. - verbose
Same as
-v. - vi
Use a
vi-style
inline editor for command entry. - viraw
Process each character as it is typed in
vi
mode (always on). - xtrace
Same as
-x.
- -p
Disable processing of the
$HOME/.profile
file and uses the file
/etc/suid_profile
instead of the
ENV
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. - -s
Sort the positional parameters. - -t
Exit after reading and executing one command. - -u
Treat unset parameters as an error when substituting. - -v
Print shell input lines as they are read. - -x
Print commands and their arguments as they are executed. - -
Turn off
-x
and
-v
options and stop examining arguments for options. - --
Do not change any of the options; useful in setting parameter
1
to a value beginning with
-.
If no arguments follow this option,
the positional parameters are unset.
%
shift [n]
Rename the positional parameters from
n+1 ...
to
1 ....
The default value of
n
is
1.
n
can be any arithmetic expression
that evaluates to a nonnegative number less than or equal to
$#.
test [expr]
Evaluate conditional expression
expr.
See
test(1)
for usage and description.
See also the
Conditional Expressions
subsection. The arithmetic comparison operators are not restricted to integers.
They allow any arithmetic expression.
The following additional primitive expressions are allowed:
- -L file
True if
file
is a symbolic link. - -e file
True if
file
exists. - file1 -nt file2
True if
file1
is newer than
file2. - file1 -ot file2
True if
file1
is older than
file2. - file1 -ef file2
True if
file1
has the same device and i-node number as
file2.
%
times
Print the accumulated user and system times for the shell
and for processes run from the shell.
%
trap [arg] [sig]...
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,
3,
QUIT,
quit,
and
SIGQUIT
all specify the same signal.
Use
kill -l
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
trap
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
DEBUG,
then
arg
is executed after each command.
If
sig
is
ERR,
arg
is executed whenever a command has a nonzero exit code.
If
sig
is
0
or
EXIT,
the command
arg
is executed on exit from the shell. With no arguments,
print a list of commands associated with each signal name. &
typeset [{-|+}LRZfilrtux[n]] [name[=value]]...
name=value
[name=value]... Assign types and a value to a local named parameter
name.
See also the
export
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.
- -L
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
-Z
option is also set.
The
-R
option is turned off.
Flagged as
leftjust n. - -R
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 assignment.
The field is left-filled with blanks or
truncated from the end if the parameter is reassigned.
The
-L
option is turned off.
Flagged as
rightjust n. - -Z
Right justify and fill with leading zeros
if the first nonblank character is a digit and the
-L
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
zerofill n
plus the flag for
-L
or
-R. - -f
Cause
name
to refer to function names rather than parameter names.
No assignments can be made to the
name
declared with the
typeset
statement.
The only other valid options are
-t
(which turns on execution tracing for this function) and
-x
(which allows the function to remain in effect across shell procedures
executed in the same process environment).
Flagged as
function. - -i
Parameter is an integer.
This makes arithmetic faster.
If
n
is nonzero it defines the output arithmetic base;
otherwise, the first assignment determines the output base.
Flagged as
integer [base n]. - -l
Convert all uppercase characters to lowercase.
The uppercase
-u
option is turned off.
Flagged as
lowercase. - -r
Mark any given
name
as "read only".
The name cannot be changed by subsequent assignment.
Flagged as
readonly. - -t
Tag the named parameters.
Tags are user-definable and have no special meaning to the shell.
Flagged as
tagged. - -u
Convert all lowercase characters to uppercase characters.
The lowercase
-l
option is turned off.
Flagged as
uppercase. - -x
Mark any given
name
for automatic export to the environment of subsequently executed commands.
Flagged as
export.
typeset
alone displays a list of parameter names,
prefixed by any flags specified above. typeset -
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. typeset +
displays the parameter names alone.
Specify one or more of the option letters to restrict the list.
Some options are incompatible with others.
ulimit [-HSacdfnst] [limit]
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
unlimited. The
-H
and
-S
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
-H
nor
-S
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
-H
is specified.
When more than one resource is specified,
the limit name and unit are printed before the value. If no option is given,
-f
is assumed.
- -a
List all of the current resource limits. - -c
The number of 512-byte blocks in the size of core dumps. - -d
The number of kilobytes in the size of the data area. - -f
The number of 512-byte blocks in files written by child processes
(files of any size can be read). - -n
The number of file descriptors. - -s
The number of kilobytes in the size of the stack area. - -t
The number of seconds to be used by each process.
umask [-S] [mask]
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
-S,
print the value in symbolic format.
Without
-S,
print the value as an octal number.
The output from either form can be used as the
mask
of a subsequent invocation of
umask.
unalias name ...
unalias -a
Remove each
name
from the alias list.
With
-a,
remove all
alias
definitions from the current shell execution environment.
See also the
alias
special command.
%
unset [-fv] name ...
Remove the named shell parameters from the parameter list.
Their values and attributes are erased.
Read-only variables cannot be unset.
With
-f,
names
refer to function names.
With
-v,
names
refer to variable names.
Unsetting
_,
ERRNO,
LINENO,
MAILCHECK,
OPTARG,
OPTIND,
RANDOM,
SECONDS,
and
TMOUT
removes their special meaning,
even if they are subsequently assigned to.
wait [job]
Wait for the specified
job
to terminate or stop, and report its status.
This status becomes the return code for the
wait
command.
Without
job,
wait for all currently active child processes to terminate or stop.
The termination status returned is that of the last process.
See the
Jobs
subsection for a description of the format of
job.
whence [-pv] name ...
For each
name,
indicate how it would be interpreted if used as a command name.
With
-v,
produce a more verbose report.
With
-p
do a path search for
name,
disregarding any use as
an alias, a function, or a reserved word.
CommentsA
word
beginning with
#
causes that word and all the following characters up to a newline
to be ignored. AliasingThe first word of each command is replaced by the text of an
alias,
if an
alias
for this word has been defined.
An
alias
name consists of any number of characters 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
blank,
the word following the alias is also checked for alias
substitution.
Aliases can be used to redefine special commands,
but cannot be used to redefine the keywords
listed in the
Compound Commands
subsection.
Aliases can be created, listed, and exported with the
alias
command and can be removed with the
unalias
command.
Exported aliases remain in effect for subshells
but must be reinitialized for separate invocations
of the shell (see the
Shell Invocation
subsection). Aliasing is performed when scripts are read,
not while they are executed.
Therefore,
for it to take effect, an
alias
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
tracked
aliases.
The value of a
tracked
alias is defined the first time the identifier
is read and becomes undefined each time the
PATH
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
-h
option of the
set
command converts each command name that is an
identifier
into a tracked alias. The following
exported aliases
are compiled into the shell but can be unset or redefined:
autoload='typeset -fu'
command='command '
functions='typeset -f'
history='fc -l'
integer='typeset -i'
local=typeset
nohup='nohup '
r='fc -e -'
stop='kill -STOP'
suspend='kill -STOP $$'
type='whence -v' Tilde SubstitutionAfter 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
/etc/passwd
file.
If a match is found, the
~
and the matched login name are replaced
by the login directory 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
HOME
parameter.
A
~
followed by a
+
or
-
is replaced by the value of
the parameter
PWD
and
OLDPWD,
respectively.
In addition, tilde substitution is attempted
when the value of a parameter assignment begins with a
~. Command SubstitutionThe 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
Quoting
subsection.
The command substitution
$(cat file)
can be replaced by the equivalent but faster
$(<file).
Command substitution of most special commands
that do not perform input/output redirection
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
Arithmetic Evaluation
subsection
for a description of arithmetic expressions. Parameter SubstitutionA
parameter
is an identifier,
one or more decimal digits, or one of the characters
!,
#,
$,
*,
-,
?,
@,
and
_.
A
named parameter
(a parameter denoted by an identifier)
has a value and zero or more attributes.
Named parameters can be assigned values and attributes
with the
typeset
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
Arithmetic Evaluation
subsection.
To assign values to an array, use
set -A name value ....
The value of all subscripts must be in the range of
0
through
1023.
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
-i
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
set
special command.
Parameter
0
is set from argument zero when the shell is invoked. Use the prefix character
$
to specify the value of a parameter for substitution.
- $parameter
- ${parameter}
- ${parameter[subscript]}
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
1,
are substituted (separated by a field separator character).
See the
Quoting
subsection. If an array parameter with subscript
*
or
@
is used, the value for each element is substituted
(separated by a field separator character). - ${#parameter}
If
parameter
is
*
or
@,
the number of positional parameters is substituted.
Otherwise, the length of the value of the
parameter
is substituted. - ${#parameter[*]}
Substitute the number of elements in the array. - ${parameter:-word}
If
parameter
is set and is nonnull, substitute its value;
otherwise, substitute
word. - ${parameter:=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. - ${parameter:?word}
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. - ${parameter:+word}
If
parameter
is set and is nonnull, substitute
word;
otherwise, substitute nothing. - ${parameter#pattern}
- ${parameter##pattern}
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 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 (''). - ${parameter%pattern}
- ${parameter%%pattern}
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 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,
pwd
is executed only if
d
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 automatically by the shell:
- 0
The string used to call the command or script,
set from invocation argument zero. - 1, 2, ...
The positional parameters. - *, @
All the set positional parameters, separated by a field separator character.
See the
Quoting
subsection. - #
The number of set positional parameters in decimal. - -
Flags supplied to the shell on invocation or by the
set
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 matching
MAIL
file when checking for mail. - !
The process number of the last background command invoked. - ERRNO
The value of
errno
as set by the most recently failed system call.
This value is system-dependent and is intended for debugging purposes. - LINENO
The line number of the current line within the script or
function being executed. - OLDPWD
The previous working directory set by the
cd
command. - OPTARG
The value of the last option argument processed by the
getopts
special command. - OPTERR
If set to 0,
OPTERR
will suppress error messages from the
getopts
special command.
OPTERR
is initially set to 1. - OPTIND
The index of the last option argument processed by the
getopts
special command. - PPID
The process number of the parent of the shell. - PWD
The present working directory set by the
cd
command. - RANDOM
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
RANDOM. - REPLY
Set by the
select
compound command, and by the
read
special command when no
name
is supplied. - SECONDS
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.
The following parameters are used by the shell:
- CDPATH
The search path for the
cd
command, a list of directories separated by colons. - COLUMNS
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
select
lists. - EDITOR
If the value of this variable ends in
emacs,
gmacs,
or
vi
and the
VISUAL
variable is not set, the corresponding option is turned on (see the
set
special command. - ENV
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
Invocation
subsection).
This file is typically used for
alias
and
function
definitions. - FCEDIT
The default editor name for the
fc
command. - FPATH
The search path for function definitions,
a list of directories separated by colons.
This path is searched when a function with the
-u
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. - HISTFILE
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
$HOME/.sh_history.
If the user is a superuser and no
HISTFILE
is given, then no history file is used.
See the
Command Reentry
subsection and the
WARNINGS
section. - HISTSIZE
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. - HOME
The default argument (home directory) for the
cd
command. - IFS
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
read.
The first character of the
IFS
parameter is used to separate arguments for the
$*
substitution (see the
Quoting
subsection).
If the value of
IFS
is space, tab, and newline, or if
IFS
is unset and it is being used to separate the results
of command or parameter substitution, any sequence of
IFS
characters serves to delimit words;
otherwise, each occurrence of a character in
IFS
serves to delimit a word.
If the value of
IFS
is null, no word splitting is done. - LANG
The locale of your system, which is made up of three parts:
language, territory, and code set.
The default is the
C
locale.
See
environ(5). - LC_ALL
The overriding value for
LANG
and the
LC_*
variables.
See
environ(5). - LC_COLLATE
The collating sequence to use when sorting names and
when character ranges occur in patterns.
See
environ(5). - LC_CTYPE
The character classification information to use.
Changing the value of
LC_CTYPE
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
LC_CTYPE
to detect nonprintable characters in the input and tries
to handle them when the
emacs,
gmacs,
or
vi
editing mode is selected.
Not starting a new shell session after setting
LC_CTYPE
may affect the display of nonprintable input characters in the
emacs,
gmacs,
or
|