4363 lines
76 KiB
HTML
4363 lines
76 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of DASH</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>DASH</H1>
|
|
Section: User Commands (1)<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
<BR>BSD mandoc<BR>
|
|
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
<B>dash</B>
|
|
|
|
- command interpreter (shell)
|
|
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<B></B>
|
|
|
|
|
|
-words
|
|
|
|
[-<B>aCefnuvxIimqVEbp</B>
|
|
|
|
]
|
|
|
|
[<B>+aCefnuvxIimqVEbp</B>
|
|
|
|
]
|
|
|
|
-words
|
|
|
|
|
|
|
|
[-<B>o </B><I>option_name</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
[<B>+o </B><I>option_name</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
-words
|
|
|
|
|
|
|
|
[<I>command_file </I>[<I>argument ... </I>]
|
|
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
<BR><B></B>
|
|
|
|
|
|
|
|
-<B>c</B>
|
|
|
|
-words
|
|
|
|
[-<B>aCefnuvxIimqVEbp</B>
|
|
|
|
]
|
|
|
|
[<B>+aCefnuvxIimqVEbp</B>
|
|
|
|
]
|
|
|
|
-words
|
|
|
|
|
|
|
|
[-<B>o </B><I>option_name</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
[<B>+o </B><I>option_name</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
-words
|
|
|
|
|
|
|
|
<I>command_string</I>
|
|
|
|
[<I>command_name </I>[<I>argument ... </I>]
|
|
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
<BR><B></B>
|
|
|
|
|
|
|
|
-<B>s</B>
|
|
|
|
-words
|
|
|
|
[-<B>aCefnuvxIimqVEbp</B>
|
|
|
|
]
|
|
|
|
[<B>+aCefnuvxIimqVEbp</B>
|
|
|
|
]
|
|
|
|
-words
|
|
|
|
|
|
|
|
[-<B>o </B><I>option_name</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
[<B>+o </B><I>option_name</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
-words
|
|
|
|
|
|
|
|
[<I>argument ...</I>
|
|
|
|
]
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
|
|
|
|
<B></B>
|
|
|
|
|
|
is the standard command interpreter for the system.
|
|
The current version of
|
|
<B></B>
|
|
|
|
|
|
is in the process of being changed to conform with the
|
|
<B>POSIX</B>
|
|
|
|
1003.2 and 1003.2a specifications for the shell.
|
|
This version has many
|
|
features which make it appear similar in some respects to the Korn shell,
|
|
but it is not a Korn shell clone (see
|
|
<A HREF="/cgi-bin/man/man2html?1+ksh">ksh</A>(1)).
|
|
|
|
|
|
Only features designated by
|
|
<B>POSIX</B>
|
|
|
|
|
|
plus a few Berkeley extensions, are being incorporated into this shell.
|
|
This man page is not intended
|
|
to be a tutorial or a complete specification of the shell.
|
|
<A NAME="lbAE"> </A>
|
|
<H3>Overview</H3>
|
|
|
|
The shell is a command that reads lines from either a file or the
|
|
terminal, interprets them, and generally executes other commands.
|
|
It is the program that is running when a user logs into the system
|
|
(although a user can select a different shell with the
|
|
<A HREF="/cgi-bin/man/man2html?1+chsh">chsh</A>(1)
|
|
|
|
|
|
command).
|
|
The shell implements a language that has flow control
|
|
constructs, a macro facility that provides a variety of features in
|
|
addition to data storage, along with built in history and line editing
|
|
capabilities.
|
|
It incorporates many features to aid interactive use and
|
|
has the advantage that the interpretative language is common to both
|
|
interactive and non-interactive use (shell scripts).
|
|
That is, commands
|
|
can be typed directly to the running shell or can be put into a file and
|
|
the file can be executed directly by the shell.
|
|
<A NAME="lbAF"> </A>
|
|
<H3>Invocation</H3>
|
|
|
|
If no args are present and if the standard input of the shell
|
|
is connected to a terminal (or if the
|
|
-<B>i</B>
|
|
|
|
flag is set),
|
|
and the
|
|
-<B>c</B>
|
|
|
|
option is not present, the shell is considered an interactive shell.
|
|
An interactive shell generally prompts before each command and handles
|
|
programming and command errors differently (as described below).
|
|
When first starting,
|
|
the shell inspects argument 0, and if it begins with a dash
|
|
`-'
|
|
|
|
|
|
the shell is also considered
|
|
a login shell.
|
|
This is normally done automatically by the system
|
|
when the user first logs in.
|
|
A login shell first reads commands
|
|
from the files
|
|
/etc/profile
|
|
|
|
and
|
|
.profile
|
|
|
|
if they exist.
|
|
If the environment variable
|
|
<B>ENV</B>
|
|
|
|
is set on entry to an interactive shell, or is set in the
|
|
.profile
|
|
|
|
of a login shell, the shell next reads
|
|
commands from the file named in
|
|
<B>ENV</B>
|
|
|
|
|
|
Therefore, a user should place commands that are to be executed only at
|
|
login time in the
|
|
.profile
|
|
|
|
file, and commands that are executed for every interactive shell inside the
|
|
<B>ENV</B>
|
|
|
|
file.
|
|
To set the
|
|
<B>ENV</B>
|
|
|
|
variable to some file, place the following line in your
|
|
.profile
|
|
|
|
of your home directory
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>ENV=$HOME/.shinit; export ENV</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
substituting for
|
|
``.shinit''
|
|
|
|
any filename you wish.
|
|
<P>
|
|
|
|
If command line arguments besides the options have been specified, then
|
|
the shell treats the first argument as the name of a file from which to
|
|
read commands (a shell script), and the remaining arguments are set as the
|
|
positional parameters of the shell ($1, $2, etc).
|
|
Otherwise, the shell
|
|
reads commands from its standard input.
|
|
<A NAME="lbAG"> </A>
|
|
<H3>Argument List Processing</H3>
|
|
|
|
All of the single letter options that have a corresponding name can be
|
|
used as an argument to the
|
|
-<B>o</B>
|
|
|
|
option.
|
|
The set
|
|
-<B>o</B>
|
|
|
|
name is provided next to the single letter option in
|
|
the description below.
|
|
Specifying a dash
|
|
``-''
|
|
|
|
turns the option on, while using a plus
|
|
``+''
|
|
|
|
disables the option.
|
|
The following options can be set from the command line or
|
|
with the
|
|
<B>set</B>
|
|
|
|
builtin (described later).
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="1"><B>-a </B><I>allexport</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Export all variables assigned to.
|
|
<DT id="2"><B>-c</B>
|
|
|
|
|
|
<DD>
|
|
Read commands from the
|
|
<I>command_string</I>
|
|
|
|
operand instead of from the standard input.
|
|
Special parameter 0 will be set from the
|
|
<I>command_name</I>
|
|
|
|
operand and the positional parameters ($1, $2, etc.)
|
|
set from the remaining argument operands.
|
|
<DT id="3"><B>-C </B><I>noclobber</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Don't overwrite existing files with
|
|
``>''
|
|
|
|
|
|
<DT id="4"><B>-e </B><I>errexit</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
If not interactive, exit immediately if any untested command fails.
|
|
The exit status of a command is considered to be
|
|
explicitly tested if the command is used to control an
|
|
<B>if</B>
|
|
|
|
|
|
<B>elif</B>
|
|
|
|
|
|
<B>while</B>
|
|
|
|
|
|
or
|
|
<B>until</B>
|
|
|
|
|
|
or if the command is the left hand operand of an
|
|
``&&''
|
|
|
|
or
|
|
``||''
|
|
|
|
operator.
|
|
<DT id="5"><B>-f </B><I>noglob</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Disable pathname expansion.
|
|
<DT id="6"><B>-n </B><I>noexec</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
If not interactive, read commands but do not execute them.
|
|
This is useful for checking the syntax of shell scripts.
|
|
<DT id="7"><B>-u </B><I>nounset</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Write a message to standard error when attempting to expand a variable
|
|
that is not set, and if the shell is not interactive, exit immediately.
|
|
<DT id="8"><B>-v </B><I>verbose</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
The shell writes its input to standard error as it is read.
|
|
Useful for debugging.
|
|
<DT id="9"><B>-x </B><I>xtrace</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Write each command to standard error (preceded by a
|
|
`+ '
|
|
|
|
|
|
before it is executed.
|
|
Useful for debugging.
|
|
<DT id="10"><B>-I </B><I>ignoreeof</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Ignore EOF's from input when interactive.
|
|
<DT id="11"><B>-i </B><I>interactive</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Force the shell to behave interactively.
|
|
<DT id="12"><B>-l</B>
|
|
|
|
|
|
<DD>
|
|
Make dash act as if it had been invoked as a login shell.
|
|
<DT id="13"><B>-m </B><I>monitor</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Turn on job control (set automatically when interactive).
|
|
<DT id="14"><B>-s </B><I>stdin</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Read commands from standard input (set automatically if no file arguments
|
|
are present).
|
|
This option has no effect when set after the shell has
|
|
already started running (i.e. with
|
|
<B>set )</B>
|
|
|
|
|
|
<DT id="15"><B>-V </B><I>vi</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Enable the built-in
|
|
<A HREF="/cgi-bin/man/man2html?1+vi">vi</A>(1)
|
|
|
|
|
|
command line editor (disables
|
|
-<B>E</B>
|
|
|
|
if it has been set).
|
|
<DT id="16"><B>-E </B><I>emacs</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Enable the built-in
|
|
<A HREF="/cgi-bin/man/man2html?1+emacs">emacs</A>(1)
|
|
|
|
|
|
command line editor (disables
|
|
-<B>V</B>
|
|
|
|
if it has been set).
|
|
<DT id="17"><B>-b </B><I>notify</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Enable asynchronous notification of background job completion.
|
|
(UNIMPLEMENTED for 4.4alpha)
|
|
<DT id="18"><B>-p </B><I>priv</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Do not attempt to reset effective uid if it does not match uid. This is not set
|
|
by default to help avoid incorrect usage by setuid root programs via <A HREF="/cgi-bin/man/man2html?3+system">system</A>(3) or
|
|
<A HREF="/cgi-bin/man/man2html?3+popen">popen</A>(3).
|
|
</DL>
|
|
<P>
|
|
|
|
<A NAME="lbAH"> </A>
|
|
<H3>Lexical Structure</H3>
|
|
|
|
The shell reads input in terms of lines from a file and breaks it up into
|
|
words at whitespace (blanks and tabs), and at certain sequences of
|
|
characters that are special to the shell called
|
|
``operators''
|
|
|
|
|
|
There are two types of operators: control operators and redirection
|
|
operators (their meaning is discussed later).
|
|
Following is a list of operators:
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="19"><B>"Control operators:"</B>
|
|
<DD>
|
|
|
|
<BLOCKQUOTE><TT>& && ( ) ; ;; | || <newline></TT></BLOCKQUOTE>
|
|
<DT id="20"><B>"Redirection operators:"</B>
|
|
<DD>
|
|
|
|
<BLOCKQUOTE><TT>< > >| << >> <& >& <<- <></TT></BLOCKQUOTE>
|
|
</DL>
|
|
<P>
|
|
|
|
<A NAME="lbAI"> </A>
|
|
<H3>Quoting</H3>
|
|
|
|
Quoting is used to remove the special meaning of certain characters or
|
|
words to the shell, such as operators, whitespace, or keywords.
|
|
There are three types of quoting: matched single quotes,
|
|
matched double quotes, and backslash.
|
|
<A NAME="lbAJ"> </A>
|
|
<H3>Backslash</H3>
|
|
|
|
A backslash preserves the literal meaning of the following
|
|
character, with the exception of
|
|
Aq newline .
|
|
|
|
A backslash preceding a
|
|
Aq newline
|
|
|
|
is treated as a line continuation.
|
|
<A NAME="lbAK"> </A>
|
|
<H3>Single Quotes</H3>
|
|
|
|
Enclosing characters in single quotes preserves the literal meaning of all
|
|
the characters (except single quotes, making it impossible to put
|
|
single-quotes in a single-quoted string).
|
|
<A NAME="lbAL"> </A>
|
|
<H3>Double Quotes</H3>
|
|
|
|
Enclosing characters within double quotes preserves the literal
|
|
meaning of all characters except dollarsign
|
|
($)
|
|
|
|
|
|
backquote
|
|
(`)
|
|
|
|
|
|
and backslash
|
|
(\)
|
|
|
|
|
|
The backslash inside double quotes is historically weird, and serves to
|
|
quote only the following characters:
|
|
|
|
<BLOCKQUOTE><TT>$ ` " \ <newline></TT></BLOCKQUOTE>
|
|
|
|
Otherwise it remains literal.
|
|
<A NAME="lbAM"> </A>
|
|
<H3>Reserved Words</H3>
|
|
|
|
Reserved words are words that have special meaning to the
|
|
shell and are recognized at the beginning of a line and
|
|
after a control operator.
|
|
The following are reserved words:
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="21"><B>! Ta </B>elif Ta fi Ta while Ta case
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
<DT id="22"><B>else Ta </B>for Ta then Ta { Ta }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
<DT id="23"><B>do Ta </B>done Ta until Ta if Ta esac
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
</DL>
|
|
<P>
|
|
|
|
<P>
|
|
|
|
Their meaning is discussed later.
|
|
<A NAME="lbAN"> </A>
|
|
<H3>Aliases</H3>
|
|
|
|
An alias is a name and corresponding value set using the
|
|
<A HREF="/cgi-bin/man/man2html?1+alias">alias</A>(1)
|
|
|
|
|
|
builtin command.
|
|
Whenever a reserved word may occur (see above),
|
|
and after checking for reserved words, the shell
|
|
checks the word to see if it matches an alias.
|
|
If it does, it replaces it in the input stream with its value.
|
|
For example, if there is an alias called
|
|
``lf''
|
|
|
|
with the value
|
|
``ls -F''
|
|
|
|
|
|
then the input:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>lf foobar Aq </TT>return
|
|
|
|
</BLOCKQUOTE>
|
|
<P>
|
|
|
|
would become
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>ls -F foobar Aq </TT>return
|
|
|
|
</BLOCKQUOTE>
|
|
<P>
|
|
|
|
Aliases provide a convenient way for naive users to create shorthands for
|
|
commands without having to learn how to create functions with arguments.
|
|
They can also be used to create lexically obscure code.
|
|
This use is discouraged.
|
|
<A NAME="lbAO"> </A>
|
|
<H3>Commands</H3>
|
|
|
|
The shell interprets the words it reads according to a language, the
|
|
specification of which is outside the scope of this man page (refer to the
|
|
BNF in the
|
|
<B>POSIX</B>
|
|
|
|
1003.2 document).
|
|
Essentially though, a line is read and if the first
|
|
word of the line (or after a control operator) is not a reserved word,
|
|
then the shell has recognized a simple command.
|
|
Otherwise, a complex
|
|
command or some other special construct may have been recognized.
|
|
<A NAME="lbAP"> </A>
|
|
<H3>Simple Commands</H3>
|
|
|
|
If a simple command has been recognized, the shell performs
|
|
the following actions:
|
|
<OL><P>
|
|
|
|
<LI>
|
|
|
|
Leading words of the form
|
|
``name=value''
|
|
|
|
are stripped off and assigned to the environment of the simple command.
|
|
Redirection operators and their arguments (as described below) are
|
|
stripped off and saved for processing.
|
|
<LI>
|
|
|
|
The remaining words are expanded as described in
|
|
the section called
|
|
``Expansions''
|
|
|
|
|
|
and the first remaining word is considered the command name and the
|
|
command is located.
|
|
The remaining words are considered the arguments of the command.
|
|
If no command name resulted, then the
|
|
``name=value''
|
|
|
|
variable assignments recognized in item 1 affect the current shell.
|
|
<LI>
|
|
|
|
Redirections are performed as described in the next section.
|
|
</OL><P>
|
|
|
|
<A NAME="lbAQ"> </A>
|
|
<H3>Redirections</H3>
|
|
|
|
Redirections are used to change where a command reads its input or sends
|
|
its output.
|
|
In general, redirections open, close, or duplicate an
|
|
existing reference to a file.
|
|
The overall format used for redirection is:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>[n] </TT><I>redir-op file</I>
|
|
|
|
|
|
|
|
</BLOCKQUOTE>
|
|
<P>
|
|
|
|
where
|
|
<I>redir-op</I>
|
|
|
|
is one of the redirection operators mentioned previously.
|
|
Following is a list of the possible redirections.
|
|
The
|
|
Bq n
|
|
|
|
is an optional number between 0 and 9, as in
|
|
`3'
|
|
|
|
(not
|
|
`Bq 3 )
|
|
|
|
'
|
|
|
|
|
|
that refers to a file descriptor.
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="24"><B>[n] > file</B>
|
|
|
|
|
|
<DD>
|
|
Redirect standard output (or n) to file.
|
|
<DT id="25"><B>[n] >| file</B>
|
|
|
|
|
|
<DD>
|
|
Same, but override the
|
|
-<B>C</B>
|
|
|
|
option.
|
|
<DT id="26"><B>[n] >> file</B>
|
|
|
|
|
|
<DD>
|
|
Append standard output (or n) to file.
|
|
<DT id="27"><B>[n] < file</B>
|
|
|
|
|
|
<DD>
|
|
Redirect standard input (or n) from file.
|
|
<DT id="28"><B>[n1] <& n2</B>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Copy file descriptor n2 as stdout (or fd n1).
|
|
fd n2.
|
|
<DT id="29"><B>[n] <&-</B>
|
|
|
|
|
|
<DD>
|
|
Close standard input (or n).
|
|
<DT id="30"><B>[n1] >& n2</B>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Copy file descriptor n2 as stdin (or fd n1).
|
|
fd n2.
|
|
<DT id="31"><B>[n] >&-</B>
|
|
|
|
|
|
<DD>
|
|
Close standard output (or n).
|
|
<DT id="32"><B>[n] <> file</B>
|
|
|
|
|
|
<DD>
|
|
Open file for reading and writing on standard input (or n).
|
|
</DL>
|
|
<P>
|
|
|
|
<P>
|
|
|
|
The following redirection is often called a
|
|
``here-document''
|
|
|
|
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="33"><B>[n]<< delimiter</B>
|
|
|
|
|
|
<DD>
|
|
|
|
<BLOCKQUOTE><TT>here-doc-text ...</TT></BLOCKQUOTE>
|
|
<B>delimiter</B>
|
|
|
|
</DL>
|
|
<P>
|
|
|
|
<P>
|
|
|
|
All the text on successive lines up to the delimiter is saved away and
|
|
made available to the command on standard input, or file descriptor n if
|
|
it is specified.
|
|
If the delimiter as specified on the initial line is
|
|
quoted, then the here-doc-text is treated literally, otherwise the text is
|
|
subjected to parameter expansion, command substitution, and arithmetic
|
|
expansion (as described in the section on
|
|
``Expansions )''
|
|
|
|
|
|
If the operator is
|
|
``<<-''
|
|
|
|
instead of
|
|
``<<''
|
|
|
|
|
|
then leading tabs in the here-doc-text are stripped.
|
|
<A NAME="lbAR"> </A>
|
|
<H3>Search and Execution</H3>
|
|
|
|
There are three types of commands: shell functions, builtin commands, and
|
|
normal programs -- and the command is searched for (by name) in that order.
|
|
They each are executed in a different way.
|
|
<P>
|
|
|
|
When a shell function is executed, all of the shell positional parameters
|
|
(except $0, which remains unchanged) are set to the arguments of the shell
|
|
function.
|
|
The variables which are explicitly placed in the environment of
|
|
the command (by placing assignments to them before the function name) are
|
|
made local to the function and are set to the values given.
|
|
Then the command given in the function definition is executed.
|
|
The positional parameters are restored to their original values
|
|
when the command completes.
|
|
This all occurs within the current shell.
|
|
<P>
|
|
|
|
Shell builtins are executed internally to the shell, without spawning a
|
|
new process.
|
|
<P>
|
|
|
|
Otherwise, if the command name doesn't match a function or builtin, the
|
|
command is searched for as a normal program in the file system (as
|
|
described in the next section).
|
|
When a normal program is executed, the shell runs the program,
|
|
passing the arguments and the environment to the program.
|
|
If the program is not a normal executable file (i.e., if it does
|
|
not begin with the "magic number" whose
|
|
<B>ASCII</B>
|
|
|
|
representation is "#!", so
|
|
<A HREF="/cgi-bin/man/man2html?2+execve">execve</A>(2)
|
|
|
|
|
|
returns
|
|
Er ENOEXEC
|
|
|
|
then) the shell will interpret the program in a subshell.
|
|
The child shell will reinitialize itself in this case,
|
|
so that the effect will be as if a
|
|
new shell had been invoked to handle the ad-hoc shell script, except that
|
|
the location of hashed commands located in the parent shell will be
|
|
remembered by the child.
|
|
<P>
|
|
|
|
Note that previous versions of this document and the source code itself
|
|
misleadingly and sporadically refer to a shell script without a magic
|
|
number as a "shell procedure".
|
|
<A NAME="lbAS"> </A>
|
|
<H3>Path Search</H3>
|
|
|
|
When locating a command, the shell first looks to see if it has a shell
|
|
function by that name.
|
|
Then it looks for a builtin command by that name.
|
|
If a builtin command is not found, one of two things happen:
|
|
<OL><P>
|
|
|
|
<LI>
|
|
|
|
Command names containing a slash are simply executed without performing
|
|
any searches.
|
|
<LI>
|
|
|
|
The shell searches each entry in
|
|
<B>PATH</B>
|
|
|
|
in turn for the command.
|
|
The value of the
|
|
<B>PATH</B>
|
|
|
|
variable should be a series of entries separated by colons.
|
|
Each entry consists of a directory name.
|
|
The current directory may be indicated
|
|
implicitly by an empty directory name, or explicitly by a single period.
|
|
</OL><P>
|
|
|
|
<A NAME="lbAT"> </A>
|
|
<H3>Command Exit Status</H3>
|
|
|
|
Each command has an exit status that can influence the behaviour
|
|
of other shell commands.
|
|
The paradigm is that a command exits
|
|
with zero for normal or success, and non-zero for failure,
|
|
error, or a false indication.
|
|
The man page for each command
|
|
should indicate the various exit codes and what they mean.
|
|
Additionally, the builtin commands return exit codes, as does
|
|
an executed shell function.
|
|
<P>
|
|
|
|
If a command consists entirely of variable assignments then the
|
|
exit status of the command is that of the last command substitution
|
|
if any, otherwise 0.
|
|
<A NAME="lbAU"> </A>
|
|
<H3>Complex Commands</H3>
|
|
|
|
Complex commands are combinations of simple commands with control
|
|
operators or reserved words, together creating a larger complex command.
|
|
More generally, a command is one of the following:
|
|
<UL><P>
|
|
|
|
<LI>
|
|
|
|
simple command
|
|
<LI>
|
|
|
|
pipeline
|
|
<LI>
|
|
|
|
list or compound-list
|
|
<LI>
|
|
|
|
compound command
|
|
<LI>
|
|
|
|
function definition
|
|
</UL><P>
|
|
|
|
<P>
|
|
|
|
Unless otherwise stated, the exit status of a command is that of the last
|
|
simple command executed by the command.
|
|
<A NAME="lbAV"> </A>
|
|
<H3>Pipelines</H3>
|
|
|
|
A pipeline is a sequence of one or more commands separated
|
|
by the control operator |.
|
|
The standard output of all but
|
|
the last command is connected to the standard input
|
|
of the next command.
|
|
The standard output of the last
|
|
command is inherited from the shell, as usual.
|
|
<P>
|
|
|
|
The format for a pipeline is:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>[!] command1 [ | command2 ...]</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
The standard output of command1 is connected to the standard input of
|
|
command2.
|
|
The standard input, standard output, or both of a command is
|
|
considered to be assigned by the pipeline before any redirection specified
|
|
by redirection operators that are part of the command.
|
|
<P>
|
|
|
|
If the pipeline is not in the background (discussed later), the shell
|
|
waits for all commands to complete.
|
|
<P>
|
|
|
|
If the reserved word ! does not precede the pipeline, the exit status is
|
|
the exit status of the last command specified in the pipeline.
|
|
Otherwise, the exit status is the logical NOT of the exit status of the
|
|
last command.
|
|
That is, if the last command returns zero, the exit status
|
|
is 1; if the last command returns greater than zero, the exit status is
|
|
zero.
|
|
<P>
|
|
|
|
Because pipeline assignment of standard input or standard output or both
|
|
takes place before redirection, it can be modified by redirection.
|
|
For example:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>$ command1 2>&1 | command2</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
sends both the standard output and standard error of command1
|
|
to the standard input of command2.
|
|
<P>
|
|
|
|
A ; or
|
|
Aq newline
|
|
|
|
terminator causes the preceding AND-OR-list (described
|
|
next) to be executed sequentially; a & causes asynchronous execution of
|
|
the preceding AND-OR-list.
|
|
<P>
|
|
|
|
Note that unlike some other shells, each process in the pipeline is a
|
|
child of the invoking shell (unless it is a shell builtin, in which case
|
|
it executes in the current shell -- but any effect it has on the
|
|
environment is wiped).
|
|
<A NAME="lbAW"> </A>
|
|
<H3>Background Commands --</H3>
|
|
|
|
|
|
If a command is terminated by the control operator ampersand (&), the
|
|
shell executes the command asynchronously -- that is, the shell does not
|
|
wait for the command to finish before executing the next command.
|
|
<P>
|
|
|
|
The format for running a command in background is:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>command1 & [command2 & ...]</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
If the shell is not interactive, the standard input of an asynchronous
|
|
command is set to
|
|
/dev/null
|
|
|
|
|
|
<A NAME="lbAX"> </A>
|
|
<H3>Lists -- Generally Speaking</H3>
|
|
|
|
A list is a sequence of zero or more commands separated by newlines,
|
|
semicolons, or ampersands, and optionally terminated by one of these three
|
|
characters.
|
|
The commands in a list are executed in the order they are written.
|
|
If command is followed by an ampersand, the shell starts the
|
|
command and immediately proceeds onto the next command; otherwise it waits
|
|
for the command to terminate before proceeding to the next one.
|
|
<A NAME="lbAY"> </A>
|
|
<H3>Short-Circuit List Operators</H3>
|
|
|
|
``&&''
|
|
|
|
and
|
|
``||''
|
|
|
|
are AND-OR list operators.
|
|
``&&''
|
|
|
|
executes the first command, and then executes the second command if and only
|
|
if the exit status of the first command is zero.
|
|
``||''
|
|
|
|
is similar, but executes the second command if and only if the exit status
|
|
of the first command is nonzero.
|
|
``&&''
|
|
|
|
and
|
|
``||''
|
|
|
|
both have the same priority.
|
|
<A NAME="lbAZ"> </A>
|
|
<H3>Flow-Control Constructs -- if, while, for, case</H3>
|
|
|
|
The syntax of the if command is
|
|
|
|
<BLOCKQUOTE>
|
|
<PRE>
|
|
if list
|
|
then list
|
|
[ elif list
|
|
then list ] ...
|
|
[ else list ]
|
|
fi
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
|
|
<P>
|
|
|
|
The syntax of the while command is
|
|
|
|
<BLOCKQUOTE>
|
|
<PRE>
|
|
while list
|
|
do list
|
|
done
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
|
|
<P>
|
|
|
|
The two lists are executed repeatedly while the exit status of the
|
|
first list is zero.
|
|
The until command is similar, but has the word
|
|
until in place of while, which causes it to
|
|
repeat until the exit status of the first list is zero.
|
|
<P>
|
|
|
|
The syntax of the for command is
|
|
|
|
<BLOCKQUOTE>
|
|
<PRE>
|
|
for variable [ in [ word ... ] ]
|
|
do list
|
|
done
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
|
|
<P>
|
|
|
|
The words following
|
|
in
|
|
|
|
are expanded, and then the list is executed repeatedly with the
|
|
variable set to each word in turn.
|
|
Omitting in word ... is equivalent to in "$@".
|
|
<P>
|
|
|
|
The syntax of the break and continue command is
|
|
|
|
<BLOCKQUOTE>
|
|
<PRE>
|
|
break [ num ]
|
|
continue [ num ]
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
|
|
<P>
|
|
|
|
Break terminates the num innermost for or while loops.
|
|
Continue continues with the next iteration of the innermost loop.
|
|
These are implemented as builtin commands.
|
|
<P>
|
|
|
|
The syntax of the case command is
|
|
|
|
<BLOCKQUOTE>
|
|
<PRE>
|
|
case word in
|
|
[(]pattern) list ;;
|
|
...
|
|
esac
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
|
|
<P>
|
|
|
|
The pattern can actually be one or more patterns (see
|
|
Sx Shell Patterns
|
|
|
|
described later), separated by
|
|
``|''
|
|
|
|
characters.
|
|
The
|
|
Do (
|
|
|
|
Dc character before the pattern is optional.
|
|
|
|
<A NAME="lbBA"> </A>
|
|
<H3>Grouping Commands Together</H3>
|
|
|
|
Commands may be grouped by writing either
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>(list)</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
or
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>{ list;</TT></BLOCKQUOTE>
|
|
|
|
<P>
|
|
|
|
The first of these executes the commands in a subshell.
|
|
Builtin commands grouped into a (list) will not affect the current shell.
|
|
The second form does not fork another shell so is slightly more efficient.
|
|
Grouping commands together this way allows you to redirect
|
|
their output as though they were one program:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE>
|
|
<PRE>
|
|
{ printf " hello " ; printf " world\n" ; } > greeting
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
|
|
<P>
|
|
|
|
Note that
|
|
``}''
|
|
|
|
must follow a control operator (here,
|
|
``;''
|
|
|
|
|
|
so that it is recognized as a reserved word and not as another command argument.
|
|
<A NAME="lbBB"> </A>
|
|
<H3>Functions</H3>
|
|
|
|
The syntax of a function definition is
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>name ( ) command</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
A function definition is an executable statement; when executed it
|
|
installs a function named name and returns an exit status of zero.
|
|
The command is normally a list enclosed between
|
|
``{''
|
|
|
|
and
|
|
``}''
|
|
|
|
|
|
<P>
|
|
|
|
Variables may be declared to be local to a function by using a local
|
|
command.
|
|
This should appear as the first statement of a function, and the syntax is
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>local [ variable | - ] ...</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
Local is implemented as a builtin command.
|
|
<P>
|
|
|
|
When a variable is made local, it inherits the initial value and exported
|
|
and readonly flags from the variable with the same name in the surrounding
|
|
scope, if there is one.
|
|
Otherwise, the variable is initially unset.
|
|
The shell uses dynamic scoping, so that if you make the variable x local to
|
|
function f, which then calls function g, references to the variable x made
|
|
inside g will refer to the variable x declared inside f, not to the global
|
|
variable named x.
|
|
<P>
|
|
|
|
The only special parameter that can be made local is
|
|
``-''
|
|
|
|
|
|
Making
|
|
``-''
|
|
|
|
local any shell options that are changed via the set command inside the
|
|
function to be restored to their original values when the function
|
|
returns.
|
|
<P>
|
|
|
|
The syntax of the return command is
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>return [ exitstatus</TT></BLOCKQUOTE>
|
|
|
|
<P>
|
|
|
|
It terminates the currently executing function.
|
|
Return is implemented as a builtin command.
|
|
<A NAME="lbBC"> </A>
|
|
<H3>Variables and Parameters</H3>
|
|
|
|
The shell maintains a set of parameters.
|
|
A parameter denoted by a name is called a variable.
|
|
When starting up, the shell turns all the environment
|
|
variables into shell variables.
|
|
New variables can be set using the form
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>name=value</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
Variables set by the user must have a name consisting solely of
|
|
alphabetics, numerics, and underscores - the first of which must not be
|
|
numeric.
|
|
A parameter can also be denoted by a number or a special
|
|
character as explained below.
|
|
<A NAME="lbBD"> </A>
|
|
<H3>Positional Parameters</H3>
|
|
|
|
A positional parameter is a parameter denoted by a number (n > 0).
|
|
The shell sets these initially to the values of its command line arguments
|
|
that follow the name of the shell script.
|
|
The
|
|
<B>set</B>
|
|
|
|
builtin can also be used to set or reset them.
|
|
<A NAME="lbBE"> </A>
|
|
<H3>Special Parameters</H3>
|
|
|
|
A special parameter is a parameter denoted by one of the following special
|
|
characters.
|
|
The value of the parameter is listed next to its character.
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="34"><B>*</B>
|
|
<DD>
|
|
Expands to the positional parameters, starting from one.
|
|
When the
|
|
expansion occurs within a double-quoted string it expands to a single
|
|
field with the value of each parameter separated by the first character of
|
|
the
|
|
<B>IFS</B>
|
|
|
|
variable, or by a
|
|
Aq space
|
|
|
|
if
|
|
<B>IFS</B>
|
|
|
|
is unset.
|
|
<DT id="35"><B>@</B>
|
|
<DD>
|
|
Expands to the positional parameters, starting from one.
|
|
When the expansion occurs within double-quotes, each positional
|
|
parameter expands as a separate argument.
|
|
If there are no positional parameters, the
|
|
expansion of @ generates zero arguments, even when @ is
|
|
double-quoted.
|
|
What this basically means, for example, is
|
|
if $1 is
|
|
``abc''
|
|
|
|
and $2 is
|
|
``def ghi''
|
|
|
|
|
|
then
|
|
Qq $@
|
|
|
|
expands to
|
|
the two arguments:
|
|
<P>
|
|
|
|
|
|
|
|
<BLOCKQUOTE><TT>" abc " " def ghi "</TT></BLOCKQUOTE>
|
|
|
|
<DT id="36"><B>#</B>
|
|
<DD>
|
|
Expands to the number of positional parameters.
|
|
<DT id="37"><B>?</B>
|
|
<DD>
|
|
Expands to the exit status of the most recent pipeline.
|
|
<DT id="38"><B>- (Hyphen.)</B>
|
|
<DD>
|
|
Expands to the current option flags (the single-letter
|
|
option names concatenated into a string) as specified on
|
|
invocation, by the set builtin command, or implicitly
|
|
by the shell.
|
|
<DT id="39"><B>$</B>
|
|
<DD>
|
|
Expands to the process ID of the invoked shell.
|
|
A subshell retains the same value of $ as its parent.
|
|
<DT id="40"><B>!</B>
|
|
<DD>
|
|
Expands to the process ID of the most recent background
|
|
command executed from the current shell.
|
|
For a pipeline, the process ID is that of the last command in the pipeline.
|
|
<DT id="41"><B>0 (Zero.)</B>
|
|
<DD>
|
|
Expands to the name of the shell or shell script.
|
|
</DL>
|
|
<P>
|
|
|
|
<A NAME="lbBF"> </A>
|
|
<H3>Word Expansions</H3>
|
|
|
|
This clause describes the various expansions that are performed on words.
|
|
Not all expansions are performed on every word, as explained later.
|
|
<P>
|
|
|
|
Tilde expansions, parameter expansions, command substitutions, arithmetic
|
|
expansions, and quote removals that occur within a single word expand to a
|
|
single field.
|
|
It is only field splitting or pathname expansion that can
|
|
create multiple fields from a single word.
|
|
The single exception to this
|
|
rule is the expansion of the special parameter @ within double-quotes, as
|
|
was described above.
|
|
<P>
|
|
|
|
The order of word expansion is:
|
|
<OL><P>
|
|
|
|
<LI>
|
|
|
|
Tilde Expansion, Parameter Expansion, Command Substitution,
|
|
Arithmetic Expansion (these all occur at the same time).
|
|
<LI>
|
|
|
|
Field Splitting is performed on fields
|
|
generated by step (1) unless the
|
|
<B>IFS</B>
|
|
|
|
variable is null.
|
|
<LI>
|
|
|
|
Pathname Expansion (unless set
|
|
-<B>f</B>
|
|
|
|
is in effect).
|
|
<LI>
|
|
|
|
Quote Removal.
|
|
</OL><P>
|
|
|
|
<P>
|
|
|
|
The $ character is used to introduce parameter expansion, command
|
|
substitution, or arithmetic evaluation.
|
|
<A NAME="lbBG"> </A>
|
|
<H3>Tilde Expansion (substituting a user's home directory)</H3>
|
|
|
|
A word beginning with an unquoted tilde character (~) is
|
|
subjected to tilde expansion.
|
|
All the characters up to
|
|
a slash (/) or the end of the word are treated as a username
|
|
and are replaced with the user's home directory.
|
|
If the username is missing (as in
|
|
~/foobar )
|
|
|
|
|
|
the tilde is replaced with the value of the
|
|
<I>HOME</I>
|
|
|
|
variable (the current user's home directory).
|
|
<A NAME="lbBH"> </A>
|
|
<H3>Parameter Expansion</H3>
|
|
|
|
The format for parameter expansion is as follows:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>${expression}</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
where expression consists of all characters until the matching
|
|
``}''
|
|
|
|
|
|
Any
|
|
``}''
|
|
|
|
escaped by a backslash or within a quoted string, and characters in
|
|
embedded arithmetic expansions, command substitutions, and variable
|
|
expansions, are not examined in determining the matching
|
|
``}''
|
|
|
|
|
|
<P>
|
|
|
|
The simplest form for parameter expansion is:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>${parameter}</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
The value, if any, of parameter is substituted.
|
|
<P>
|
|
|
|
The parameter name or symbol can be enclosed in braces, which are
|
|
optional except for positional parameters with more than one digit or
|
|
when parameter is followed by a character that could be interpreted as
|
|
part of the name.
|
|
If a parameter expansion occurs inside double-quotes:
|
|
<OL><P>
|
|
|
|
<LI>
|
|
|
|
Pathname expansion is not performed on the results of the expansion.
|
|
<LI>
|
|
|
|
Field splitting is not performed on the results of the
|
|
expansion, with the exception of @.
|
|
</OL><P>
|
|
|
|
<P>
|
|
|
|
In addition, a parameter expansion can be modified by using one of the
|
|
following formats.
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="42"><B>${parameter:-word}</B>
|
|
<DD>
|
|
Use Default Values.
|
|
If parameter is unset or null, the expansion of word
|
|
is substituted; otherwise, the value of parameter is substituted.
|
|
<DT id="43"><B>${parameter:=word}</B>
|
|
<DD>
|
|
Assign Default Values.
|
|
If parameter is unset or null, the expansion of
|
|
word is assigned to parameter.
|
|
In all cases, the final value of parameter is substituted.
|
|
Only variables, not positional parameters or special
|
|
parameters, can be assigned in this way.
|
|
<DT id="44"><B>${parameter:?[word]}</B>
|
|
<DD>
|
|
Indicate Error if Null or Unset.
|
|
If parameter is unset or null, the
|
|
expansion of word (or a message indicating it is unset if word is omitted)
|
|
is written to standard error and the shell exits with a nonzero exit status.
|
|
Otherwise, the value of parameter is substituted.
|
|
An interactive shell need not exit.
|
|
<DT id="45"><B>${parameter:+word}</B>
|
|
<DD>
|
|
Use Alternative Value.
|
|
If parameter is unset or null, null is
|
|
substituted; otherwise, the expansion of word is substituted.
|
|
</DL>
|
|
<P>
|
|
|
|
<P>
|
|
|
|
In the parameter expansions shown previously, use of the colon in the
|
|
format results in a test for a parameter that is unset or null; omission
|
|
of the colon results in a test for a parameter that is only unset.
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="46"><B>${#parameter}</B>
|
|
<DD>
|
|
String Length.
|
|
The length in characters of the value of parameter.
|
|
</DL>
|
|
<P>
|
|
|
|
<P>
|
|
|
|
The following four varieties of parameter expansion provide for substring
|
|
processing.
|
|
In each case, pattern matching notation (see
|
|
Sx Shell Patterns ) ,
|
|
|
|
rather than regular expression notation, is used to evaluate the patterns.
|
|
If parameter is * or @, the result of the expansion is unspecified.
|
|
Enclosing the full parameter expansion string in double-quotes does not
|
|
cause the following four varieties of pattern characters to be quoted,
|
|
whereas quoting characters within the braces has this effect.
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="47"><B>${parameter%word}</B>
|
|
<DD>
|
|
Remove Smallest Suffix Pattern.
|
|
The word is expanded to produce a pattern.
|
|
The parameter expansion then results in parameter, with the
|
|
smallest portion of the suffix matched by the pattern deleted.
|
|
<DT id="48"><B>${parameter%%word}</B>
|
|
<DD>
|
|
Remove Largest Suffix Pattern.
|
|
The word is expanded to produce a pattern.
|
|
The parameter expansion then results in parameter, with the largest
|
|
portion of the suffix matched by the pattern deleted.
|
|
<DT id="49"><B>${parameter#word}</B>
|
|
<DD>
|
|
Remove Smallest Prefix Pattern.
|
|
The word is expanded to produce a pattern.
|
|
The parameter expansion then results in parameter, with the
|
|
smallest portion of the prefix matched by the pattern deleted.
|
|
<DT id="50"><B>${parameter##word}</B>
|
|
<DD>
|
|
Remove Largest Prefix Pattern.
|
|
The word is expanded to produce a pattern.
|
|
The parameter expansion then results in parameter, with the largest
|
|
portion of the prefix matched by the pattern deleted.
|
|
</DL>
|
|
<P>
|
|
|
|
<A NAME="lbBI"> </A>
|
|
<H3>Command Substitution</H3>
|
|
|
|
Command substitution allows the output of a command to be substituted in
|
|
place of the command name itself.
|
|
Command substitution occurs when the command is enclosed as follows:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>$(command)</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
or
|
|
Po ``backquoted''
|
|
|
|
|
|
|
|
version
|
|
Pc :
|
|
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>`command`</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
The shell expands the command substitution by executing command in a
|
|
subshell environment and replacing the command substitution with the
|
|
standard output of the command, removing sequences of one or more
|
|
Ao newline Ac Ns s
|
|
|
|
at the end of the substitution.
|
|
(Embedded
|
|
Ao newline Ac Ns s
|
|
|
|
before
|
|
the end of the output are not removed; however, during field splitting,
|
|
they may be translated into
|
|
Ao space Ac Ns s ,
|
|
|
|
depending on the value of
|
|
<B>IFS</B>
|
|
|
|
and quoting that is in effect.)
|
|
<A NAME="lbBJ"> </A>
|
|
<H3>Arithmetic Expansion</H3>
|
|
|
|
Arithmetic expansion provides a mechanism for evaluating an arithmetic
|
|
expression and substituting its value.
|
|
The format for arithmetic expansion is as follows:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>$((expression))</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
The expression is treated as if it were in double-quotes, except
|
|
that a double-quote inside the expression is not treated specially.
|
|
The shell expands all tokens in the expression for parameter expansion,
|
|
command substitution, and quote removal.
|
|
<P>
|
|
|
|
Next, the shell treats this as an arithmetic expression and
|
|
substitutes the value of the expression.
|
|
<A NAME="lbBK"> </A>
|
|
<H3>White Space Splitting (Field Splitting)</H3>
|
|
|
|
After parameter expansion, command substitution, and
|
|
arithmetic expansion the shell scans the results of
|
|
expansions and substitutions that did not occur in double-quotes for
|
|
field splitting and multiple fields can result.
|
|
<P>
|
|
|
|
The shell treats each character of the
|
|
<B>IFS</B>
|
|
|
|
as a delimiter and uses the delimiters to split the results of parameter
|
|
expansion and command substitution into fields.
|
|
<A NAME="lbBL"> </A>
|
|
<H3>Pathname Expansion (File Name Generation)</H3>
|
|
|
|
Unless the
|
|
-<B>f</B>
|
|
|
|
flag is set, file name generation is performed after word splitting is
|
|
complete.
|
|
Each word is viewed as a series of patterns, separated by slashes.
|
|
The process of expansion replaces the word with the names of all
|
|
existing files whose names can be formed by replacing each pattern with a
|
|
string that matches the specified pattern.
|
|
There are two restrictions on
|
|
this: first, a pattern cannot match a string containing a slash, and
|
|
second, a pattern cannot match a string starting with a period unless the
|
|
first character of the pattern is a period.
|
|
The next section describes the
|
|
patterns used for both Pathname Expansion and the
|
|
<B>case</B>
|
|
|
|
command.
|
|
<A NAME="lbBM"> </A>
|
|
<H3>Shell Patterns</H3>
|
|
|
|
A pattern consists of normal characters, which match themselves,
|
|
and meta-characters.
|
|
The meta-characters are
|
|
``!''
|
|
|
|
|
|
``*''
|
|
|
|
|
|
``?''
|
|
|
|
|
|
and
|
|
``[''
|
|
|
|
|
|
These characters lose their special meanings if they are quoted.
|
|
When command or variable substitution is performed
|
|
and the dollar sign or back quotes are not double quoted,
|
|
the value of the variable or the output of
|
|
the command is scanned for these characters and they are turned into
|
|
meta-characters.
|
|
<P>
|
|
|
|
An asterisk
|
|
(``*''
|
|
|
|
)
|
|
|
|
matches any string of characters.
|
|
A question mark matches any single character.
|
|
A left bracket
|
|
(``[''
|
|
|
|
)
|
|
|
|
introduces a character class.
|
|
The end of the character class is indicated by a
|
|
(``]''
|
|
|
|
)
|
|
|
|
|
|
if the
|
|
``]''
|
|
|
|
is missing then the
|
|
``[''
|
|
|
|
matches a
|
|
``[''
|
|
|
|
rather than introducing a character class.
|
|
A character class matches any of the characters between the square brackets.
|
|
A range of characters may be specified using a minus sign.
|
|
The character class may be complemented
|
|
by making an exclamation point the first character of the character class.
|
|
<P>
|
|
|
|
To include a
|
|
``]''
|
|
|
|
in a character class, make it the first character listed (after the
|
|
``!''
|
|
|
|
|
|
if any).
|
|
To include a minus sign, make it the first or last character listed.
|
|
<A NAME="lbBN"> </A>
|
|
<H3>Builtins</H3>
|
|
|
|
This section lists the builtin commands which are builtin because they
|
|
need to perform some operation that can't be performed by a separate
|
|
process.
|
|
In addition to these, there are several other commands that may
|
|
be builtin for efficiency (e.g.
|
|
<A HREF="/cgi-bin/man/man2html?1+printf">printf</A>(1),
|
|
|
|
|
|
<A HREF="/cgi-bin/man/man2html?1+echo">echo</A>(1),
|
|
|
|
|
|
<A HREF="/cgi-bin/man/man2html?1+test">test</A>(1),
|
|
|
|
|
|
etc).
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="51"><B>:</B>
|
|
<DD>
|
|
<DT id="52"><B>true</B>
|
|
<DD>
|
|
A null command that returns a 0 (true) exit value.
|
|
<DT id="53"><B>. file</B>
|
|
<DD>
|
|
The commands in the specified file are read and executed by the shell.
|
|
<DT id="54"><B>alias </B>[<I>name </I><B></B>[<I>=string ...</I>
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
<DD>
|
|
If
|
|
<I>name=string</I>
|
|
|
|
is specified, the shell defines the alias
|
|
<I>name</I>
|
|
|
|
with value
|
|
<I>string</I>
|
|
|
|
|
|
If just
|
|
<I>name</I>
|
|
|
|
is specified, the value of the alias
|
|
<I>name</I>
|
|
|
|
is printed.
|
|
With no arguments, the
|
|
<B>alias</B>
|
|
|
|
builtin prints the
|
|
names and values of all defined aliases (see
|
|
<B>unalias )</B>
|
|
|
|
|
|
<DT id="55"><B>bg [ </B><I>job ] ...</I>
|
|
|
|
|
|
<DD>
|
|
Continue the specified jobs (or the current job if no
|
|
jobs are given) in the background.
|
|
<DT id="56"><B>
|
|
command</B>
|
|
|
|
[-<B>p</B>
|
|
|
|
]
|
|
|
|
[-<B>v</B>
|
|
|
|
]
|
|
|
|
[-<B>V</B>
|
|
|
|
]
|
|
|
|
<I>command</I>
|
|
|
|
[<I>arg ...</I>
|
|
|
|
]
|
|
|
|
<DD>
|
|
|
|
<DD>Execute the specified command but ignore shell functions when searching
|
|
for it.
|
|
(This is useful when you
|
|
have a shell function with the same name as a builtin command.)
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="57"><B>-p</B>
|
|
|
|
|
|
<DD>
|
|
search for command using a
|
|
<B>PATH</B>
|
|
|
|
that guarantees to find all the standard utilities.
|
|
<DT id="58"><B>-V</B>
|
|
|
|
|
|
<DD>
|
|
Do not execute the command but
|
|
search for the command and print the resolution of the
|
|
command search.
|
|
This is the same as the type builtin.
|
|
<DT id="59"><B>-v</B>
|
|
|
|
|
|
<DD>
|
|
Do not execute the command but
|
|
search for the command and print the absolute pathname
|
|
of utilities, the name for builtins or the expansion of aliases.
|
|
</DL>
|
|
<P>
|
|
|
|
<DT id="60"><B>cd </B><I>file ...</I>
|
|
|
|
|
|
<DD>
|
|
|
|
<DT id="61"><B>
|
|
cd </B>[-<B>LP</B>
|
|
|
|
]
|
|
|
|
|
|
|
|
[<I>directory</I>
|
|
|
|
]
|
|
|
|
<DD>
|
|
|
|
<DD>Switch to the specified directory (default
|
|
<B>HOME )</B>
|
|
|
|
|
|
If an entry for
|
|
<B>CDPATH</B>
|
|
|
|
appears in the environment of the
|
|
<B>cd</B>
|
|
|
|
command or the shell variable
|
|
<B>CDPATH</B>
|
|
|
|
is set and the directory name does not begin with a slash, then the
|
|
directories listed in
|
|
<B>CDPATH</B>
|
|
|
|
will be searched for the specified directory.
|
|
The format of
|
|
<B>CDPATH</B>
|
|
|
|
is the same as that of
|
|
<B>PATH</B>
|
|
|
|
|
|
If a single dash is specified as the argument, it will be replaced by the
|
|
value of
|
|
<B>OLDPWD</B>
|
|
|
|
|
|
The
|
|
<B>cd</B>
|
|
|
|
command will print out the name of the
|
|
directory that it actually switched to if this is different from the name
|
|
that the user gave.
|
|
These may be different either because the
|
|
<B>CDPATH</B>
|
|
|
|
mechanism was used or because the argument is a single dash.
|
|
The
|
|
-<B>P</B>
|
|
|
|
option causes the physical directory structure to be used, that is, all
|
|
symbolic links are resolved to their respective values. The
|
|
-<B>L</B>
|
|
|
|
option turns off the effect of any preceding
|
|
-<B>P</B>
|
|
|
|
options.
|
|
<DT id="62"><B>
|
|
echo </B>[-<B>n</B>
|
|
|
|
]
|
|
|
|
|
|
|
|
<I>args... </I>
|
|
|
|
<DD>
|
|
|
|
<DD>Print the arguments on the standard output, separated by spaces.
|
|
Unless the
|
|
-<B>n</B>
|
|
|
|
option is present, a newline is output following the arguments.
|
|
<P>
|
|
|
|
If any of the following sequences of characters is encountered during
|
|
output, the sequence is not output. Instead, the specified action is
|
|
performed:
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="63"><B>\b</B>
|
|
|
|
|
|
<DD>
|
|
A backspace character is output.
|
|
<DT id="64"><B>\c</B>
|
|
|
|
|
|
<DD>
|
|
Subsequent output is suppressed. This is normally used at the end of the
|
|
last argument to suppress the trailing newline that
|
|
<B>echo</B>
|
|
|
|
would otherwise output.
|
|
<DT id="65"><B>\e</B>
|
|
|
|
|
|
<DD>
|
|
Outputs an escape character (ESC).
|
|
<DT id="66"><B>\f</B>
|
|
|
|
|
|
<DD>
|
|
Output a form feed.
|
|
<DT id="67"><B>\n</B>
|
|
|
|
|
|
<DD>
|
|
Output a newline character.
|
|
<DT id="68"><B>\r</B>
|
|
|
|
|
|
<DD>
|
|
Output a carriage return.
|
|
<DT id="69"><B>\t</B>
|
|
|
|
|
|
<DD>
|
|
Output a (horizontal) tab character.
|
|
<DT id="70"><B>\v</B>
|
|
|
|
|
|
<DD>
|
|
Output a vertical tab.
|
|
<DT id="71"><B>\0 </B><I>digits</I>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Output the character whose value is given by zero to three octal digits.
|
|
If there are zero digits, a nul character is output.
|
|
<DT id="72"><B>\\</B>
|
|
|
|
|
|
<DD>
|
|
Output a backslash.
|
|
</DL>
|
|
<P>
|
|
|
|
<P>
|
|
|
|
All other backslash sequences elicit undefined behaviour.
|
|
<DT id="73"><B>eval </B><I>string ...</I>
|
|
|
|
|
|
<DD>
|
|
Concatenate all the arguments with spaces.
|
|
Then re-parse and execute the command.
|
|
<DT id="74"><B>exec </B>[<I>command arg ...</I>
|
|
|
|
]
|
|
|
|
|
|
<DD>
|
|
Unless command is omitted, the shell process is replaced with the
|
|
specified program (which must be a real program, not a shell builtin or
|
|
function).
|
|
Any redirections on the
|
|
<B>exec</B>
|
|
|
|
command are marked as permanent, so that they are not undone when the
|
|
<B>exec</B>
|
|
|
|
command finishes.
|
|
<DT id="75"><B>exit </B>[<I>exitstatus</I>
|
|
|
|
]
|
|
|
|
|
|
<DD>
|
|
Terminate the shell process.
|
|
If
|
|
<I>exitstatus</I>
|
|
|
|
is given it is used as the exit status of the shell; otherwise the
|
|
exit status of the preceding command is used.
|
|
<DT id="76"><B>export </B><I>name ...</I>
|
|
|
|
|
|
<DD>
|
|
<DT id="77"><B>export -p</B>
|
|
|
|
|
|
<DD>
|
|
The specified names are exported so that they will appear in the
|
|
environment of subsequent commands.
|
|
The only way to un-export a variable is to unset it.
|
|
The shell allows the value of a variable to be set at the
|
|
same time it is exported by writing
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>export name=value</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
With no arguments the export command lists the names of all exported variables.
|
|
With the
|
|
-<B>p</B>
|
|
|
|
option specified the output will be formatted suitably for non-interactive use.
|
|
<DT id="78"><B>
|
|
fc </B>[-<B>e </B><I>editor</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
[<I>first </I>[<I>last</I>
|
|
|
|
]
|
|
|
|
|
|
|
|
]
|
|
|
|
<DD>
|
|
|
|
<DT id="79"><B>
|
|
fc -l</B>
|
|
|
|
|
|
|
|
[-<B>nr</B>
|
|
|
|
]
|
|
|
|
[<I>first </I>[<I>last</I>
|
|
|
|
]
|
|
|
|
|
|
|
|
]
|
|
|
|
<DD>
|
|
|
|
<DT id="80"><B>
|
|
fc -s </B>[<I>old=new</I>
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
[<I>first</I>
|
|
|
|
]
|
|
|
|
<DD>
|
|
|
|
<DD>The
|
|
<B>fc</B>
|
|
|
|
builtin lists, or edits and re-executes, commands previously entered
|
|
to an interactive shell.
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="81"><B>-e editor</B>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Use the editor named by editor to edit the commands.
|
|
The editor string is a command name, subject to search via the
|
|
<B>PATH</B>
|
|
|
|
variable.
|
|
The value in the
|
|
<B>FCEDIT</B>
|
|
|
|
variable is used as a default when
|
|
-<B>e</B>
|
|
|
|
is not specified.
|
|
If
|
|
<B>FCEDIT</B>
|
|
|
|
is null or unset, the value of the
|
|
<B>EDITOR</B>
|
|
|
|
variable is used.
|
|
If
|
|
<B>EDITOR</B>
|
|
|
|
is null or unset,
|
|
<A HREF="/cgi-bin/man/man2html?1+ed">ed</A>(1)
|
|
|
|
|
|
is used as the editor.
|
|
<DT id="82"><B>-l (ell)</B>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
List the commands rather than invoking an editor on them.
|
|
The commands are written in the sequence indicated by
|
|
the first and last operands, as affected by
|
|
-<B>r</B>
|
|
|
|
|
|
with each command preceded by the command number.
|
|
<DT id="83"><B>-n</B>
|
|
|
|
|
|
<DD>
|
|
Suppress command numbers when listing with -l.
|
|
<DT id="84"><B>-r</B>
|
|
|
|
|
|
<DD>
|
|
Reverse the order of the commands listed (with
|
|
-<B>l</B>
|
|
|
|
|
|
or edited (with neither
|
|
-<B>l</B>
|
|
|
|
nor
|
|
-<B>s )</B>
|
|
|
|
|
|
<DT id="85"><B>-s</B>
|
|
|
|
|
|
<DD>
|
|
Re-execute the command without invoking an editor.
|
|
<DT id="86"><B>first</B>
|
|
<DD>
|
|
<DT id="87"><B>last</B>
|
|
<DD>
|
|
Select the commands to list or edit.
|
|
The number of previous commands that
|
|
can be accessed are determined by the value of the
|
|
<B>HISTSIZE</B>
|
|
|
|
variable.
|
|
The value of first or last or both are one of the following:
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="88"><B>[+]number</B>
|
|
<DD>
|
|
A positive number representing a command number; command numbers can be
|
|
displayed with the
|
|
-<B>l</B>
|
|
|
|
option.
|
|
<DT id="89"><B>-number</B>
|
|
|
|
|
|
<DD>
|
|
A negative decimal number representing the command that was executed
|
|
number of commands previously.
|
|
For example, -1 is the immediately previous command.
|
|
</DL>
|
|
<P>
|
|
|
|
<DT id="90"><B>string</B>
|
|
<DD>
|
|
A string indicating the most recently entered command that begins with
|
|
that string.
|
|
If the old=new operand is not also specified with
|
|
-<B>s</B>
|
|
|
|
|
|
the string form of the first operand cannot contain an embedded equal sign.
|
|
</DL>
|
|
<P>
|
|
|
|
<P>
|
|
|
|
The following environment variables affect the execution of fc:
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="91"><B>FCEDIT</B>
|
|
|
|
|
|
<DD>
|
|
Name of the editor to use.
|
|
<DT id="92"><B>HISTSIZE</B>
|
|
|
|
|
|
<DD>
|
|
The number of previous commands that are accessible.
|
|
</DL>
|
|
<P>
|
|
|
|
<DT id="93"><B>fg </B>[<I>job</I>
|
|
|
|
]
|
|
|
|
|
|
<DD>
|
|
Move the specified job or the current job to the foreground.
|
|
<DT id="94"><B>getopts </B><I>optstring var</I>
|
|
|
|
|
|
<DD>
|
|
The
|
|
<B>POSIX</B>
|
|
|
|
<B>getopts</B>
|
|
|
|
command, not to be confused with the
|
|
<I>Bell Labs</I>
|
|
|
|
-derived
|
|
<A HREF="/cgi-bin/man/man2html?1+getopt">getopt</A>(1).
|
|
|
|
|
|
<P>
|
|
|
|
The first argument should be a series of letters, each of which may be
|
|
optionally followed by a colon to indicate that the option requires an
|
|
argument.
|
|
The variable specified is set to the parsed option.
|
|
<P>
|
|
|
|
The
|
|
<B>getopts</B>
|
|
|
|
command deprecates the older
|
|
<A HREF="/cgi-bin/man/man2html?1+getopt">getopt</A>(1)
|
|
|
|
|
|
utility due to its handling of arguments containing whitespace.
|
|
<P>
|
|
|
|
The
|
|
<B>getopts</B>
|
|
|
|
builtin may be used to obtain options and their arguments
|
|
from a list of parameters.
|
|
When invoked,
|
|
<B>getopts</B>
|
|
|
|
places the value of the next option from the option string in the list in
|
|
the shell variable specified by
|
|
<I>var</I>
|
|
|
|
and its index in the shell variable
|
|
<B>OPTIND</B>
|
|
|
|
|
|
When the shell is invoked,
|
|
<B>OPTIND</B>
|
|
|
|
is initialized to 1.
|
|
For each option that requires an argument, the
|
|
<B>getopts</B>
|
|
|
|
builtin will place it in the shell variable
|
|
<B>OPTARG</B>
|
|
|
|
|
|
If an option is not allowed for in the
|
|
<I>optstring</I>
|
|
|
|
|
|
then
|
|
<B>OPTARG</B>
|
|
|
|
will be unset.
|
|
<P>
|
|
|
|
<I>optstring</I>
|
|
|
|
is a string of recognized option letters (see
|
|
<A HREF="/cgi-bin/man/man2html?3+getopt">getopt</A>(3)).
|
|
|
|
|
|
If a letter is followed by a colon, the option is expected to have an
|
|
argument which may or may not be separated from it by white space.
|
|
If an option character is not found where expected,
|
|
<B>getopts</B>
|
|
|
|
will set the variable
|
|
<I>var</I>
|
|
|
|
to a
|
|
``?''
|
|
|
|
|
|
<B>getopts</B>
|
|
|
|
will then unset
|
|
<B>OPTARG</B>
|
|
|
|
and write output to standard error.
|
|
By specifying a colon as the first character of
|
|
<I>optstring</I>
|
|
|
|
all errors will be ignored.
|
|
<P>
|
|
|
|
After the last option
|
|
<B>getopts</B>
|
|
|
|
will return a non-zero value and set
|
|
<I>var</I>
|
|
|
|
to
|
|
``?''
|
|
|
|
|
|
<P>
|
|
|
|
The following code fragment shows how one might process the arguments
|
|
for a command that can take the options
|
|
[a]
|
|
|
|
and
|
|
[b]
|
|
|
|
|
|
and the option
|
|
[c]
|
|
|
|
|
|
which requires an argument.
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE>
|
|
<PRE>
|
|
while getopts abc: f
|
|
do
|
|
case $f in
|
|
a | b) flag=$f;;
|
|
c) carg=$OPTARG;;
|
|
\?) echo $USAGE; exit 1;;
|
|
esac
|
|
done
|
|
shift `expr $OPTIND - 1`
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
|
|
<P>
|
|
|
|
This code will accept any of the following as equivalent:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE>
|
|
<PRE>
|
|
cmd -acarg file file
|
|
cmd -a -c arg file file
|
|
cmd -carg -a file file
|
|
cmd -a -carg -- file file
|
|
</PRE>
|
|
</BLOCKQUOTE>
|
|
|
|
<DT id="95"><B>hash -rv </B><I>command ...</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
The shell maintains a hash table which remembers the
|
|
locations of commands.
|
|
With no arguments whatsoever,
|
|
the
|
|
<B>hash</B>
|
|
|
|
command prints out the contents of this table.
|
|
Entries which have not been looked at since the last
|
|
<B>cd</B>
|
|
|
|
command are marked with an asterisk; it is possible for these entries
|
|
to be invalid.
|
|
<P>
|
|
|
|
With arguments, the
|
|
<B>hash</B>
|
|
|
|
command removes the specified commands from the hash table (unless
|
|
they are functions) and then locates them.
|
|
With the
|
|
-<B>v</B>
|
|
|
|
option, hash prints the locations of the commands as it finds them.
|
|
The
|
|
-<B>r</B>
|
|
|
|
option causes the hash command to delete all the entries in the hash table
|
|
except for functions.
|
|
<DT id="96"><B>pwd </B>[-<B>LP</B>
|
|
|
|
]
|
|
|
|
|
|
<DD>
|
|
builtin command remembers what the current directory
|
|
is rather than recomputing it each time.
|
|
This makes it faster.
|
|
However, if the current directory is renamed, the builtin version of
|
|
<B>pwd</B>
|
|
|
|
will continue to print the old name for the directory.
|
|
The
|
|
-<B>P</B>
|
|
|
|
option causes the physical value of the current working directory to be shown,
|
|
that is, all symbolic links are resolved to their respective values. The
|
|
-<B>L</B>
|
|
|
|
option turns off the effect of any preceding
|
|
-<B>P</B>
|
|
|
|
options.
|
|
<DT id="97"><B>
|
|
read </B>[-<B>p </B><I>prompt</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
[-<B>r</B>
|
|
|
|
]
|
|
|
|
<I>variable</I>
|
|
|
|
[<I>...</I>
|
|
|
|
]
|
|
|
|
<DD>
|
|
|
|
<DD>The prompt is printed if the
|
|
-<B>p</B>
|
|
|
|
option is specified and the standard input is a terminal.
|
|
Then a line is read from the standard input.
|
|
The trailing newline is deleted from the
|
|
line and the line is split as described in the section on word splitting
|
|
above, and the pieces are assigned to the variables in order.
|
|
At least one variable must be specified.
|
|
If there are more pieces than variables, the remaining pieces
|
|
(along with the characters in
|
|
<B>IFS</B>
|
|
|
|
that separated them) are assigned to the last variable.
|
|
If there are more variables than pieces,
|
|
the remaining variables are assigned the null string.
|
|
The
|
|
<B>read</B>
|
|
|
|
builtin will indicate success unless EOF is encountered on input, in
|
|
which case failure is returned.
|
|
<P>
|
|
|
|
By default, unless the
|
|
-<B>r</B>
|
|
|
|
option is specified, the backslash
|
|
``\''
|
|
|
|
acts as an escape character, causing the following character to be treated
|
|
literally.
|
|
If a backslash is followed by a newline, the backslash and the
|
|
newline will be deleted.
|
|
<DT id="98"><B>readonly </B><I>name ...</I>
|
|
|
|
|
|
<DD>
|
|
<DT id="99"><B>readonly -p</B>
|
|
|
|
|
|
<DD>
|
|
The specified names are marked as read only, so that they cannot be
|
|
subsequently modified or unset.
|
|
The shell allows the value of a variable
|
|
to be set at the same time it is marked read only by writing
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>readonly name=value</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
With no arguments the readonly command lists the names of all read only
|
|
variables.
|
|
With the
|
|
-<B>p</B>
|
|
|
|
option specified the output will be formatted suitably for non-interactive use.
|
|
<P>
|
|
|
|
<DT id="100"><B>
|
|
printf </B><I>format</I>
|
|
|
|
|
|
|
|
[<I>arguments ...</I>
|
|
|
|
]
|
|
|
|
<DD>
|
|
|
|
<B>printf</B>
|
|
|
|
<DD>formats and prints its arguments, after the first, under control
|
|
of the
|
|
<I>format </I>
|
|
|
|
|
|
The
|
|
<I>format</I>
|
|
|
|
is a character string which contains three types of objects: plain characters,
|
|
which are simply copied to standard output, character escape sequences which
|
|
are converted and copied to the standard output, and format specifications,
|
|
each of which causes printing of the next successive
|
|
<I>argument </I>
|
|
|
|
|
|
<P>
|
|
|
|
The
|
|
<I>arguments</I>
|
|
|
|
after the first are treated as strings if the corresponding format is
|
|
either
|
|
<B>b</B>
|
|
|
|
|
|
<B>c</B>
|
|
|
|
or
|
|
<B>s</B>
|
|
|
|
|
|
otherwise it is evaluated as a C constant, with the following extensions:
|
|
<P>
|
|
|
|
<UL><P>
|
|
|
|
<LI>
|
|
|
|
A leading plus or minus sign is allowed.
|
|
<LI>
|
|
|
|
If the leading character is a single or double quote, the value is the
|
|
<B>ASCII</B>
|
|
|
|
code of the next character.
|
|
</UL><P>
|
|
|
|
<P>
|
|
|
|
The format string is reused as often as necessary to satisfy the
|
|
<I>arguments </I>
|
|
|
|
|
|
Any extra format specifications are evaluated with zero or the null
|
|
string.
|
|
<P>
|
|
|
|
Character escape sequences are in backslash notation as defined in
|
|
St -ansiC .
|
|
|
|
The characters and their meanings are as follows:
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="101"><B>\a</B>
|
|
|
|
|
|
<DD>
|
|
Write a <bell> character.
|
|
<DT id="102"><B>\b</B>
|
|
|
|
|
|
<DD>
|
|
Write a <backspace> character.
|
|
<DT id="103"><B>\e</B>
|
|
|
|
|
|
<DD>
|
|
Write an <escape> (ESC) character.
|
|
<DT id="104"><B>\f</B>
|
|
|
|
|
|
<DD>
|
|
Write a <form-feed> character.
|
|
<DT id="105"><B>\n</B>
|
|
|
|
|
|
<DD>
|
|
Write a <new-line> character.
|
|
<DT id="106"><B>\r</B>
|
|
|
|
|
|
<DD>
|
|
Write a <carriage return> character.
|
|
<DT id="107"><B>\t</B>
|
|
|
|
|
|
<DD>
|
|
Write a <tab> character.
|
|
<DT id="108"><B>\v</B>
|
|
|
|
|
|
<DD>
|
|
Write a <vertical tab> character.
|
|
<DT id="109"><B>\\</B>
|
|
|
|
|
|
<DD>
|
|
Write a backslash character.
|
|
<DT id="110"><B>\ </B><I>num</I>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Write an 8-bit character whose
|
|
<B>ASCII</B>
|
|
|
|
value is the 1-, 2-, or 3-digit
|
|
octal number
|
|
<I>num</I>
|
|
|
|
|
|
</DL>
|
|
<P>
|
|
|
|
<P>
|
|
|
|
Each format specification is introduced by the percent character
|
|
(``%'').
|
|
The remainder of the format specification includes,
|
|
in the following order:
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="111"><B>"Zero or more of the following flags:"</B>
|
|
<DD>
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="112"><B>#</B>
|
|
|
|
|
|
<DD>
|
|
A `#' character
|
|
specifying that the value should be printed in an ``alternative form''.
|
|
For
|
|
<B>b</B>
|
|
|
|
|
|
<B>c</B>
|
|
|
|
|
|
<B>d</B>
|
|
|
|
|
|
and
|
|
<B>s</B>
|
|
|
|
formats, this option has no effect.
|
|
For the
|
|
<B>o</B>
|
|
|
|
format the precision of the number is increased to force the first
|
|
character of the output string to a zero.
|
|
For the
|
|
<B>x</B>
|
|
|
|
(<B>X</B>
|
|
|
|
)
|
|
|
|
format, a non-zero result has the string
|
|
<B>0x</B>
|
|
|
|
(<B>0X</B>
|
|
|
|
)
|
|
|
|
prepended to it.
|
|
For
|
|
<B>e </B>
|
|
|
|
|
|
<B>E</B>
|
|
|
|
|
|
<B>f </B>
|
|
|
|
|
|
<B>g</B>
|
|
|
|
|
|
and
|
|
<B>G</B>
|
|
|
|
formats, the result will always contain a decimal point, even if no
|
|
digits follow the point (normally, a decimal point only appears in the
|
|
results of those formats if a digit follows the decimal point).
|
|
For
|
|
<B>g</B>
|
|
|
|
and
|
|
<B>G</B>
|
|
|
|
formats, trailing zeros are not removed from the result as they
|
|
would otherwise be.
|
|
<DT id="113"><B>-</B>
|
|
|
|
|
|
<DD>
|
|
A minus sign `-' which specifies
|
|
<I>left adjustment</I>
|
|
|
|
of the output in the indicated field;
|
|
<DT id="114"><B>+</B>
|
|
|
|
|
|
<DD>
|
|
A `+' character specifying that there should always be
|
|
a sign placed before the number when using signed formats.
|
|
<DT id="115"><B>` '
|
|
|
|
</B>
|
|
<DD>
|
|
A space specifying that a blank should be left before a positive number
|
|
for a signed format.
|
|
A `+' overrides a space if both are used;
|
|
<DT id="116"><B>0</B>
|
|
|
|
|
|
<DD>
|
|
A zero `0' character indicating that zero-padding should be used
|
|
rather than blank-padding.
|
|
A `-' overrides a `0' if both are used;
|
|
</DL>
|
|
<P>
|
|
|
|
<DT id="117"><B>"Field Width:"</B>
|
|
<DD>
|
|
An optional digit string specifying a
|
|
<I>field width</I>
|
|
|
|
|
|
if the output string has fewer characters than the field width it will
|
|
be blank-padded on the left (or right, if the left-adjustment indicator
|
|
has been given) to make up the field width (note that a leading zero
|
|
is a flag, but an embedded zero is part of a field width);
|
|
<DT id="118"><B>Precision</B>
|
|
<DD>
|
|
|
|
An optional period,
|
|
`<B>.</B>
|
|
|
|
'
|
|
|
|
|
|
followed by an optional digit string giving a
|
|
<I>precision</I>
|
|
|
|
which specifies the number of digits to appear after the decimal point,
|
|
for
|
|
<B>e</B>
|
|
|
|
and
|
|
<B>f</B>
|
|
|
|
formats, or the maximum number of bytes to be printed
|
|
from a string
|
|
|
|
( <B>b</B>
|
|
|
|
|
|
|
|
|
|
and
|
|
<B>s</B>
|
|
|
|
formats); if the digit string is missing, the precision is treated
|
|
as zero;
|
|
<DT id="119"><B>Format</B>
|
|
<DD>
|
|
|
|
A character which indicates the type of format to use (one of
|
|
<B>diouxXfwEgGbcs )</B>
|
|
|
|
|
|
</DL>
|
|
<P>
|
|
|
|
<P>
|
|
|
|
A field width or precision may be
|
|
`<B>*</B>
|
|
|
|
'
|
|
|
|
instead of a digit string.
|
|
In this case an
|
|
<I>argument</I>
|
|
|
|
supplies the field width or precision.
|
|
<P>
|
|
|
|
The format characters and their meanings are:
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="120"><B>diouXx </B>The
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
<I>argument</I>
|
|
|
|
is printed as a signed decimal (d or i), unsigned octal, unsigned decimal,
|
|
or unsigned hexadecimal (X or x), respectively.
|
|
<DT id="121"><B>f</B>
|
|
|
|
|
|
<DD>
|
|
The
|
|
<I>argument</I>
|
|
|
|
is printed in the style
|
|
|
|
[-]ddd <B>. ddd</B>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
where the number of d's
|
|
after the decimal point is equal to the precision specification for
|
|
the argument.
|
|
If the precision is missing, 6 digits are given; if the precision
|
|
is explicitly 0, no digits and no decimal point are printed.
|
|
<DT id="122"><B>eE</B>
|
|
|
|
|
|
<DD>
|
|
The
|
|
<I>argument</I>
|
|
|
|
is printed in the style
|
|
|
|
[-]d <B>. ddd e ±dd</B>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
where there
|
|
is one digit before the decimal point and the number after is equal to
|
|
the precision specification for the argument; when the precision is
|
|
missing, 6 digits are produced.
|
|
An upper-case E is used for an `E' format.
|
|
<DT id="123"><B>gG</B>
|
|
|
|
|
|
<DD>
|
|
The
|
|
<I>argument</I>
|
|
|
|
is printed in style
|
|
<B>f</B>
|
|
|
|
or in style
|
|
<B>e</B>
|
|
|
|
(<B>E</B>
|
|
|
|
)
|
|
|
|
whichever gives full precision in minimum space.
|
|
<DT id="124"><B>b</B>
|
|
|
|
|
|
<DD>
|
|
Characters from the string
|
|
<I>argument</I>
|
|
|
|
are printed with backslash-escape sequences expanded.
|
|
<BR>
|
|
|
|
The following additional backslash-escape sequences are supported:
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="125"><B>\c</B>
|
|
|
|
|
|
<DD>
|
|
Causes
|
|
<B></B>
|
|
|
|
|
|
to ignore any remaining characters in the string operand containing it,
|
|
any remaining string operands, and any additional characters in
|
|
the format operand.
|
|
<DT id="126"><B>\0 </B><I>num</I>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
Write an 8-bit character whose
|
|
<B>ASCII</B>
|
|
|
|
value is the 1-, 2-, or 3-digit
|
|
octal number
|
|
<I>num</I>
|
|
|
|
|
|
</DL>
|
|
<P>
|
|
|
|
<DT id="127"><B>c</B>
|
|
|
|
|
|
<DD>
|
|
The first character of
|
|
<I>argument</I>
|
|
|
|
is printed.
|
|
<DT id="128"><B>s</B>
|
|
|
|
|
|
<DD>
|
|
Characters from the string
|
|
<I>argument</I>
|
|
|
|
are printed until the end is reached or until the number of bytes
|
|
indicated by the precision specification is reached; if the
|
|
precision is omitted, all characters in the string are printed.
|
|
<DT id="129"><B>%</B>
|
|
|
|
|
|
<DD>
|
|
Print a `%'; no argument is used.
|
|
</DL>
|
|
<P>
|
|
|
|
<P>
|
|
|
|
In no case does a non-existent or small field width cause truncation of
|
|
a field; padding takes place only if the specified field width exceeds
|
|
the actual width.
|
|
<DT id="130"><B>
|
|
set</B>
|
|
|
|
[{
|
|
-<B>options | +options | --</B>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<I>arg ...</I>
|
|
|
|
]
|
|
<DD>
|
|
|
|
<DD>The
|
|
<B>set</B>
|
|
|
|
command performs three different functions.
|
|
<P>
|
|
|
|
With no arguments, it lists the values of all shell variables.
|
|
<P>
|
|
|
|
If options are given, it sets the specified option
|
|
flags, or clears them as described in the section called
|
|
Sx Argument List Processing .
|
|
|
|
As a special case, if the option is -o or +o and no argument is
|
|
supplied, the shell prints the settings of all its options. If the
|
|
option is -o, the settings are printed in a human-readable format; if
|
|
the option is +o, the settings are printed in a format suitable for
|
|
reinput to the shell to affect the same option settings.
|
|
<P>
|
|
|
|
The third use of the set command is to set the values of the shell's
|
|
positional parameters to the specified args.
|
|
To change the positional
|
|
parameters without changing any options, use
|
|
``--''
|
|
|
|
as the first argument to set.
|
|
If no args are present, the set command
|
|
will clear all the positional parameters (equivalent to executing
|
|
``shift $# .''
|
|
|
|
|
|
<DT id="131"><B>shift </B>[<I>n</I>
|
|
|
|
]
|
|
|
|
|
|
<DD>
|
|
Shift the positional parameters n times.
|
|
A
|
|
<B>shift</B>
|
|
|
|
sets the value of
|
|
<I>$1</I>
|
|
|
|
to the value of
|
|
<I>$2</I>
|
|
|
|
|
|
the value of
|
|
<I>$2</I>
|
|
|
|
to the value of
|
|
<I>$3</I>
|
|
|
|
|
|
and so on, decreasing
|
|
the value of
|
|
<I>$#</I>
|
|
|
|
by one.
|
|
If n is greater than the number of positional parameters,
|
|
<B>shift</B>
|
|
|
|
will issue an error message, and exit with return status 2.
|
|
<DT id="132"><B>test </B><I>expression</I>
|
|
|
|
|
|
<DD>
|
|
<DT id="133"><B>[ </B><I>expression </I><B>]</B>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
The
|
|
<B>test</B>
|
|
|
|
utility evaluates the expression and, if it evaluates
|
|
to true, returns a zero (true) exit status; otherwise
|
|
it returns 1 (false).
|
|
If there is no expression, test also
|
|
returns 1 (false).
|
|
<P>
|
|
|
|
All operators and flags are separate arguments to the
|
|
<B>test</B>
|
|
|
|
utility.
|
|
<P>
|
|
|
|
The following primaries are used to construct expression:
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="134"><B>-b </B><I>file</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file</I>
|
|
|
|
exists and is a block special
|
|
file.
|
|
<DT id="135"><B>-c </B><I>file</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file</I>
|
|
|
|
exists and is a character
|
|
special file.
|
|
<DT id="136"><B>-d </B><I>file</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file</I>
|
|
|
|
exists and is a directory.
|
|
<DT id="137"><B>-e </B><I>file</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file</I>
|
|
|
|
exists (regardless of type).
|
|
<DT id="138"><B>-f </B><I>file</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file</I>
|
|
|
|
exists and is a regular file.
|
|
<DT id="139"><B>-g </B><I>file</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file</I>
|
|
|
|
exists and its set group ID flag
|
|
is set.
|
|
<DT id="140"><B>-h </B><I>file</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file</I>
|
|
|
|
exists and is a symbolic link.
|
|
<DT id="141"><B>-k </B><I>file</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file</I>
|
|
|
|
exists and its sticky bit is set.
|
|
<DT id="142"><B>-n </B><I>string</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if the length of
|
|
<I>string</I>
|
|
|
|
is nonzero.
|
|
<DT id="143"><B>-p </B><I>file</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file</I>
|
|
|
|
is a named pipe
|
|
Po Tn FIFO Pc .
|
|
|
|
<DT id="144"><B>-r </B><I>file</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file</I>
|
|
|
|
exists and is readable.
|
|
<DT id="145"><B>-s </B><I>file</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file</I>
|
|
|
|
exists and has a size greater
|
|
than zero.
|
|
<DT id="146"><B>-t </B><I>file_descriptor</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if the file whose file descriptor number
|
|
is
|
|
<I>file_descriptor</I>
|
|
|
|
is open and is associated with a terminal.
|
|
<DT id="147"><B>-u </B><I>file</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file</I>
|
|
|
|
exists and its set user ID flag
|
|
is set.
|
|
<DT id="148"><B>-w </B><I>file</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file</I>
|
|
|
|
exists and is writable.
|
|
True
|
|
indicates only that the write flag is on.
|
|
The file is not writable on a read-only file
|
|
system even if this test indicates true.
|
|
<DT id="149"><B>-x </B><I>file</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file</I>
|
|
|
|
exists and is executable.
|
|
True
|
|
indicates only that the execute flag is on.
|
|
If
|
|
<I>file</I>
|
|
|
|
is a directory, true indicates that
|
|
<I>file</I>
|
|
|
|
can be searched.
|
|
<DT id="150"><B>-z </B><I>string</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if the length of
|
|
<I>string</I>
|
|
|
|
is zero.
|
|
<DT id="151"><B>-L </B><I>file</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file</I>
|
|
|
|
exists and is a symbolic link.
|
|
This operator is retained for compatibility with previous versions of
|
|
this program.
|
|
Do not rely on its existence; use
|
|
-<B>h</B>
|
|
|
|
instead.
|
|
<DT id="152"><B>-O </B><I>file</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file</I>
|
|
|
|
exists and its owner matches the effective user id of this process.
|
|
<DT id="153"><B>-G </B><I>file</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file</I>
|
|
|
|
exists and its group matches the effective group id of this process.
|
|
<DT id="154"><B>-S </B><I>file</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file</I>
|
|
|
|
exists and is a socket.
|
|
<DT id="155"><B></B><I>file1 -</I><B>nt </B><I>file2</I>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file1</I>
|
|
|
|
and
|
|
<I>file2</I>
|
|
|
|
exist and
|
|
<I>file1</I>
|
|
|
|
is newer than
|
|
<I>file2</I>
|
|
|
|
|
|
<DT id="156"><B></B><I>file1 -</I><B>ot </B><I>file2</I>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file1</I>
|
|
|
|
and
|
|
<I>file2</I>
|
|
|
|
exist and
|
|
<I>file1</I>
|
|
|
|
is older than
|
|
<I>file2</I>
|
|
|
|
|
|
<DT id="157"><B></B><I>file1 -</I><B>ef </B><I>file2</I>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>file1</I>
|
|
|
|
and
|
|
<I>file2</I>
|
|
|
|
exist and refer to the same file.
|
|
<DT id="158"><B></B><I>string</I>
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>string</I>
|
|
|
|
is not the null
|
|
string.
|
|
<DT id="159"><B></B><I>s1 </I><B>= </B><I>s2</I>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if the strings
|
|
<I>s1</I>
|
|
|
|
and
|
|
<I>s2</I>
|
|
|
|
are identical.
|
|
<DT id="160"><B></B><I>s1 </I><B>!= </B><I>s2</I>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if the strings
|
|
<I>s1</I>
|
|
|
|
and
|
|
<I>s2</I>
|
|
|
|
are not identical.
|
|
<DT id="161"><B></B><I>s1 </I><B>< </B><I>s2</I>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if string
|
|
<I>s1</I>
|
|
|
|
comes before
|
|
<I>s2</I>
|
|
|
|
based on the ASCII value of their characters.
|
|
<DT id="162"><B></B><I>s1 </I><B>> </B><I>s2</I>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if string
|
|
<I>s1</I>
|
|
|
|
comes after
|
|
<I>s2</I>
|
|
|
|
based on the ASCII value of their characters.
|
|
<DT id="163"><B></B><I>n1 -</I><B>eq </B><I>n2</I>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if the integers
|
|
<I>n1</I>
|
|
|
|
and
|
|
<I>n2</I>
|
|
|
|
are algebraically
|
|
equal.
|
|
<DT id="164"><B></B><I>n1 -</I><B>ne </B><I>n2</I>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if the integers
|
|
<I>n1</I>
|
|
|
|
and
|
|
<I>n2</I>
|
|
|
|
are not
|
|
algebraically equal.
|
|
<DT id="165"><B></B><I>n1 -</I><B>gt </B><I>n2</I>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if the integer
|
|
<I>n1</I>
|
|
|
|
is algebraically
|
|
greater than the integer
|
|
<I>n2</I>
|
|
|
|
|
|
<DT id="166"><B></B><I>n1 -</I><B>ge </B><I>n2</I>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if the integer
|
|
<I>n1</I>
|
|
|
|
is algebraically
|
|
greater than or equal to the integer
|
|
<I>n2</I>
|
|
|
|
|
|
<DT id="167"><B></B><I>n1 -</I><B>lt </B><I>n2</I>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if the integer
|
|
<I>n1</I>
|
|
|
|
is algebraically less
|
|
than the integer
|
|
<I>n2</I>
|
|
|
|
|
|
<DT id="168"><B></B><I>n1 -</I><B>le </B><I>n2</I>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if the integer
|
|
<I>n1</I>
|
|
|
|
is algebraically less
|
|
than or equal to the integer
|
|
<I>n2</I>
|
|
|
|
|
|
</DL>
|
|
<P>
|
|
|
|
<P>
|
|
|
|
These primaries can be combined with the following operators:
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="169"><B>! </B><I>expression</I>
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if
|
|
<I>expression</I>
|
|
|
|
is false.
|
|
<DT id="170"><B></B><I>expression1 -</I><B>a </B><I>expression2</I>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if both
|
|
<I>expression1</I>
|
|
|
|
and
|
|
<I>expression2</I>
|
|
|
|
are true.
|
|
<DT id="171"><B></B><I>expression1 -</I><B>o </B><I>expression2</I>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if either
|
|
<I>expression1</I>
|
|
|
|
or
|
|
<I>expression2</I>
|
|
|
|
are true.
|
|
<DT id="172"><B>( </B><I>expression </I><B>)</B>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<DD>
|
|
True if expression is true.
|
|
</DL>
|
|
<P>
|
|
|
|
<P>
|
|
|
|
The
|
|
-<B>a</B>
|
|
|
|
operator has higher precedence than the
|
|
-<B>o</B>
|
|
|
|
operator.
|
|
<DT id="173"><B>times</B>
|
|
<DD>
|
|
Print the accumulated user and system times for the shell and for processes
|
|
run from the shell. The return status is 0.
|
|
<DT id="174"><B>
|
|
trap</B>
|
|
|
|
[<I>action signal ...</I>
|
|
|
|
|
|
|
|
]
|
|
|
|
<DD>
|
|
|
|
<DD>Cause the shell to parse and execute action when any of the specified
|
|
signals are received.
|
|
The signals are specified by signal number or as the name of the signal.
|
|
If
|
|
<I>signal</I>
|
|
|
|
is
|
|
<B>0</B>
|
|
|
|
or
|
|
<B>EXIT</B>
|
|
|
|
|
|
the action is executed when the shell exits.
|
|
<I>action</I>
|
|
|
|
may be empty
|
|
<B>( '' )</B>
|
|
|
|
|
|
which causes the specified signals to be ignored.
|
|
With
|
|
<I>action</I>
|
|
|
|
omitted or set to `-' the specified signals are set to their default action.
|
|
When the shell forks off a subshell, it resets trapped (but not ignored)
|
|
signals to the default action.
|
|
The
|
|
<B>trap</B>
|
|
|
|
command has no effect on signals that were
|
|
ignored on entry to the shell.
|
|
<B>trap</B>
|
|
|
|
without any arguments cause it to write a list of signals and their
|
|
associated action to the standard output in a format that is suitable
|
|
as an input to the shell that achieves the same trapping results.
|
|
<P>
|
|
|
|
Examples:
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>trap</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
List trapped signals and their corresponding action
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>trap '' INT QUIT tstp 30</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
Ignore signals INT QUIT TSTP USR1
|
|
<P>
|
|
|
|
|
|
<BLOCKQUOTE><TT>trap date INT</TT></BLOCKQUOTE>
|
|
<P>
|
|
|
|
Print date upon receiving signal INT
|
|
<DT id="175"><B>type </B>[<I>name ...</I>
|
|
|
|
]
|
|
|
|
|
|
<DD>
|
|
Interpret each name as a command and print the resolution of the command
|
|
search.
|
|
Possible resolutions are:
|
|
shell keyword, alias, shell builtin,
|
|
command, tracked alias and not found.
|
|
For aliases the alias expansion is
|
|
printed; for commands and tracked aliases the complete pathname of the
|
|
command is printed.
|
|
<DT id="176"><B>ulimit
|
|
</B>
|
|
|
|
[-<B>H | -S</B>
|
|
|
|
|
|
|
|
]
|
|
|
|
[-<B>a | -tfdscmlpnv </B>[<I>value</I>
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
]
|
|
|
|
<DD>
|
|
|
|
<DD>Inquire about or set the hard or soft limits on processes or set new
|
|
limits.
|
|
The choice between hard limit (which no process is allowed to
|
|
violate, and which may not be raised once it has been lowered) and soft
|
|
limit (which causes processes to be signaled but not necessarily killed,
|
|
and which may be raised) is made with these flags:
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="177"><B>-H</B>
|
|
|
|
|
|
<DD>
|
|
set or inquire about hard limits
|
|
<DT id="178"><B>-S</B>
|
|
|
|
|
|
<DD>
|
|
set or inquire about soft limits.
|
|
If neither
|
|
-<B>H</B>
|
|
|
|
nor
|
|
-<B>S</B>
|
|
|
|
is specified, the soft limit is displayed or both limits are set.
|
|
If both are specified, the last one wins.
|
|
</DL>
|
|
<P>
|
|
|
|
<P>
|
|
|
|
The limit to be interrogated or set, then, is chosen by specifying
|
|
any one of these flags:
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="179"><B>-a</B>
|
|
|
|
|
|
<DD>
|
|
show all the current limits
|
|
<DT id="180"><B>-t</B>
|
|
|
|
|
|
<DD>
|
|
show or set the limit on CPU time (in seconds)
|
|
<DT id="181"><B>-f</B>
|
|
|
|
|
|
<DD>
|
|
show or set the limit on the largest file that can be created
|
|
(in 512-byte blocks)
|
|
<DT id="182"><B>-d</B>
|
|
|
|
|
|
<DD>
|
|
show or set the limit on the data segment size of a process (in kilobytes)
|
|
<DT id="183"><B>-s</B>
|
|
|
|
|
|
<DD>
|
|
show or set the limit on the stack size of a process (in kilobytes)
|
|
<DT id="184"><B>-c</B>
|
|
|
|
|
|
<DD>
|
|
show or set the limit on the largest core dump size that can be produced
|
|
(in 512-byte blocks)
|
|
<DT id="185"><B>-m</B>
|
|
|
|
|
|
<DD>
|
|
show or set the limit on the total physical memory that can be
|
|
in use by a process (in kilobytes)
|
|
<DT id="186"><B>-l</B>
|
|
|
|
|
|
<DD>
|
|
show or set the limit on how much memory a process can lock with
|
|
<A HREF="/cgi-bin/man/man2html?2+mlock">mlock</A>(2)
|
|
|
|
|
|
(in kilobytes)
|
|
<DT id="187"><B>-p</B>
|
|
|
|
|
|
<DD>
|
|
show or set the limit on the number of processes this user can
|
|
have at one time
|
|
<DT id="188"><B>-n</B>
|
|
|
|
|
|
<DD>
|
|
show or set the limit on the number files a process can have open at once
|
|
<DT id="189"><B>-v</B>
|
|
|
|
|
|
<DD>
|
|
show or set the limit on the total virtual memory that can be
|
|
in use by a process (in kilobytes)
|
|
<DT id="190"><B>-r</B>
|
|
|
|
|
|
<DD>
|
|
show or set the limit on the real-time scheduling priority of a process
|
|
</DL>
|
|
<P>
|
|
|
|
<P>
|
|
|
|
If none of these is specified, it is the limit on file size that is shown
|
|
or set.
|
|
If value is specified, the limit is set to that number; otherwise
|
|
the current limit is displayed.
|
|
<P>
|
|
|
|
Limits of an arbitrary process can be displayed or set using the
|
|
<A HREF="/cgi-bin/man/man2html?8+sysctl">sysctl</A>(8)
|
|
|
|
|
|
utility.
|
|
<P>
|
|
|
|
<DT id="191"><B>umask </B>[<I>mask</I>
|
|
|
|
]
|
|
|
|
|
|
<DD>
|
|
Set the value of umask (see
|
|
<A HREF="/cgi-bin/man/man2html?2+umask">umask</A>(2))
|
|
|
|
|
|
to the specified octal value.
|
|
If the argument is omitted, the umask value is printed.
|
|
<DT id="192"><B>unalias
|
|
</B>
|
|
|
|
[-<B>a</B>
|
|
|
|
]
|
|
|
|
[<I>name</I>
|
|
|
|
]
|
|
|
|
<DD>
|
|
|
|
<DD>If
|
|
<I>name</I>
|
|
|
|
is specified, the shell removes that alias.
|
|
If
|
|
-<B>a</B>
|
|
|
|
is specified, all aliases are removed.
|
|
<DT id="193"><B>unset
|
|
</B>
|
|
|
|
[-<B>fv</B>
|
|
|
|
]
|
|
|
|
<I>name ...</I>
|
|
|
|
<DD>
|
|
|
|
<DD>The specified variables and functions are unset and unexported.
|
|
If
|
|
-<B>f</B>
|
|
|
|
or
|
|
-<B>v</B>
|
|
|
|
is specified, the corresponding function or variable is unset, respectively.
|
|
If a given name corresponds to both a variable and a function, and no
|
|
options are given, only the variable is unset.
|
|
<DT id="194"><B>wait </B>[<I>job</I>
|
|
|
|
]
|
|
|
|
|
|
<DD>
|
|
Wait for the specified job to complete and return the exit status of the
|
|
last process in the job.
|
|
If the argument is omitted, wait for all jobs to
|
|
complete and return an exit status of zero.
|
|
</DL>
|
|
<P>
|
|
|
|
<A NAME="lbBO"> </A>
|
|
<H3>Command Line Editing</H3>
|
|
|
|
When
|
|
<B></B>
|
|
|
|
|
|
is being used interactively from a terminal, the current command
|
|
and the command history (see
|
|
<B>fc</B>
|
|
|
|
in
|
|
Sx Builtins )
|
|
|
|
can be edited using vi-mode command-line editing.
|
|
This mode uses commands, described below,
|
|
similar to a subset of those described in the vi man page.
|
|
The command
|
|
`set'
|
|
|
|
-o vi
|
|
enables vi-mode editing and places sh into vi insert mode.
|
|
With vi-mode
|
|
enabled, sh can be switched between insert mode and command mode.
|
|
It is similar to vi: typing
|
|
Aq ESC
|
|
|
|
enters vi command mode.
|
|
Hitting
|
|
Aq return
|
|
|
|
while in command mode will pass the line to the shell.
|
|
<A NAME="lbBP"> </A>
|
|
<H2>EXIT STATUS</H2>
|
|
|
|
Errors that are detected by the shell, such as a syntax error, will cause the
|
|
shell to exit with a non-zero exit status.
|
|
If the shell is not an
|
|
interactive shell, the execution of the shell file will be aborted.
|
|
Otherwise
|
|
the shell will return the exit status of the last command executed, or
|
|
if the exit builtin is used with a numeric argument, it will return the
|
|
argument.
|
|
<A NAME="lbBQ"> </A>
|
|
<H2>ENVIRONMENT</H2>
|
|
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="195"><B>HOME</B>
|
|
|
|
|
|
<DD>
|
|
Set automatically by
|
|
<A HREF="/cgi-bin/man/man2html?1+login">login</A>(1)
|
|
|
|
|
|
from the user's login directory in the password file
|
|
(<A HREF="/cgi-bin/man/man2html?4+passwd">passwd</A>(4)
|
|
|
|
)
|
|
|
|
|
|
This environment variable also functions as the default argument for the
|
|
cd builtin.
|
|
<DT id="196"><B>PATH</B>
|
|
|
|
|
|
<DD>
|
|
The default search path for executables.
|
|
See the above section
|
|
Sx Path Search .
|
|
|
|
<DT id="197"><B>CDPATH</B>
|
|
|
|
|
|
<DD>
|
|
The search path used with the cd builtin.
|
|
<DT id="198"><B>MAIL</B>
|
|
|
|
|
|
<DD>
|
|
The name of a mail file, that will be checked for the arrival of new mail.
|
|
Overridden by
|
|
<B>MAILPATH</B>
|
|
|
|
|
|
<DT id="199"><B>MAILCHECK</B>
|
|
|
|
|
|
<DD>
|
|
The frequency in seconds that the shell checks for the arrival of mail
|
|
in the files specified by the
|
|
<B>MAILPATH</B>
|
|
|
|
or the
|
|
<B>MAIL</B>
|
|
|
|
file.
|
|
If set to 0, the check will occur at each prompt.
|
|
<DT id="200"><B>MAILPATH</B>
|
|
|
|
|
|
<DD>
|
|
A colon
|
|
``:''
|
|
|
|
separated list of file names, for the shell to check for incoming mail.
|
|
This environment setting overrides the
|
|
<B>MAIL</B>
|
|
|
|
setting.
|
|
There is a maximum of 10 mailboxes that can be monitored at once.
|
|
<DT id="201"><B>PS1</B>
|
|
|
|
|
|
<DD>
|
|
The primary prompt string, which defaults to
|
|
``$ ''
|
|
|
|
|
|
unless you are the superuser, in which case it defaults to
|
|
``# ''
|
|
|
|
|
|
<DT id="202"><B>PS2</B>
|
|
|
|
|
|
<DD>
|
|
The secondary prompt string, which defaults to
|
|
``> ''
|
|
|
|
|
|
<DT id="203"><B>PS4</B>
|
|
|
|
|
|
<DD>
|
|
Output before each line when execution trace (set -x) is enabled,
|
|
defaults to
|
|
``+ ''
|
|
|
|
|
|
<DT id="204"><B>IFS</B>
|
|
|
|
|
|
<DD>
|
|
Input Field Separators.
|
|
This is normally set to
|
|
Aq space ,
|
|
|
|
Aq tab ,
|
|
|
|
and
|
|
Aq newline .
|
|
|
|
See the
|
|
Sx White Space Splitting
|
|
|
|
section for more details.
|
|
<DT id="205"><B>TERM</B>
|
|
|
|
|
|
<DD>
|
|
The default terminal setting for the shell.
|
|
This is inherited by
|
|
children of the shell, and is used in the history editing modes.
|
|
<DT id="206"><B>HISTSIZE</B>
|
|
|
|
|
|
<DD>
|
|
The number of lines in the history buffer for the shell.
|
|
<DT id="207"><B>PWD</B>
|
|
|
|
|
|
<DD>
|
|
The logical value of the current working directory. This is set by the
|
|
<B>cd</B>
|
|
|
|
command.
|
|
<DT id="208"><B>OLDPWD</B>
|
|
|
|
|
|
<DD>
|
|
The previous logical value of the current working directory. This is set by
|
|
the
|
|
<B>cd</B>
|
|
|
|
command.
|
|
<DT id="209"><B>PPID</B>
|
|
|
|
|
|
<DD>
|
|
The process ID of the parent process of the shell.
|
|
</DL>
|
|
<P>
|
|
|
|
<A NAME="lbBR"> </A>
|
|
<H2>FILES</H2>
|
|
|
|
<DL COMPACT>
|
|
<P>
|
|
|
|
<DT id="210"><B>$HOME/.profile
|
|
|
|
</B>
|
|
<DD>
|
|
<DT id="211"><B>/etc/profile
|
|
|
|
</B>
|
|
<DD>
|
|
</DL>
|
|
<P>
|
|
|
|
<A NAME="lbBS"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<A HREF="/cgi-bin/man/man2html?1+csh">csh</A>(1),
|
|
|
|
|
|
<A HREF="/cgi-bin/man/man2html?1+echo">echo</A>(1),
|
|
|
|
|
|
<A HREF="/cgi-bin/man/man2html?1+getopt">getopt</A>(1),
|
|
|
|
|
|
<A HREF="/cgi-bin/man/man2html?1+ksh">ksh</A>(1),
|
|
|
|
|
|
<A HREF="/cgi-bin/man/man2html?1+login">login</A>(1),
|
|
|
|
|
|
<A HREF="/cgi-bin/man/man2html?1+printf">printf</A>(1),
|
|
|
|
|
|
<A HREF="/cgi-bin/man/man2html?1+test">test</A>(1),
|
|
|
|
|
|
<A HREF="/cgi-bin/man/man2html?3+getopt">getopt</A>(3),
|
|
|
|
|
|
<A HREF="/cgi-bin/man/man2html?5+passwd">passwd</A>(5),
|
|
|
|
|
|
|
|
<A HREF="/cgi-bin/man/man2html?7+environ">environ</A>(7),
|
|
|
|
|
|
<A HREF="/cgi-bin/man/man2html?8+sysctl">sysctl</A>(8)
|
|
|
|
|
|
<A NAME="lbBT"> </A>
|
|
<H2>HISTORY</H2>
|
|
|
|
<B></B>
|
|
|
|
|
|
is a POSIX-compliant implementation of /bin/sh that aims to be as small as
|
|
possible.
|
|
<B></B>
|
|
|
|
|
|
is a direct descendant of the NetBSD version of ash (the Almquist SHell),
|
|
ported to Linux in early 1997.
|
|
It was renamed to
|
|
<B></B>
|
|
|
|
|
|
in 2002.
|
|
<A NAME="lbBU"> </A>
|
|
<H2>BUGS</H2>
|
|
|
|
Setuid shell scripts should be avoided at all costs, as they are a
|
|
significant security risk.
|
|
<P>
|
|
|
|
PS1, PS2, and PS4 should be subject to parameter expansion before
|
|
being displayed.
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="212"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="213"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="214"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DL>
|
|
<DT id="215"><A HREF="#lbAE">Overview</A><DD>
|
|
<DT id="216"><A HREF="#lbAF">Invocation</A><DD>
|
|
<DT id="217"><A HREF="#lbAG">Argument List Processing</A><DD>
|
|
<DT id="218"><A HREF="#lbAH">Lexical Structure</A><DD>
|
|
<DT id="219"><A HREF="#lbAI">Quoting</A><DD>
|
|
<DT id="220"><A HREF="#lbAJ">Backslash</A><DD>
|
|
<DT id="221"><A HREF="#lbAK">Single Quotes</A><DD>
|
|
<DT id="222"><A HREF="#lbAL">Double Quotes</A><DD>
|
|
<DT id="223"><A HREF="#lbAM">Reserved Words</A><DD>
|
|
<DT id="224"><A HREF="#lbAN">Aliases</A><DD>
|
|
<DT id="225"><A HREF="#lbAO">Commands</A><DD>
|
|
<DT id="226"><A HREF="#lbAP">Simple Commands</A><DD>
|
|
<DT id="227"><A HREF="#lbAQ">Redirections</A><DD>
|
|
<DT id="228"><A HREF="#lbAR">Search and Execution</A><DD>
|
|
<DT id="229"><A HREF="#lbAS">Path Search</A><DD>
|
|
<DT id="230"><A HREF="#lbAT">Command Exit Status</A><DD>
|
|
<DT id="231"><A HREF="#lbAU">Complex Commands</A><DD>
|
|
<DT id="232"><A HREF="#lbAV">Pipelines</A><DD>
|
|
<DT id="233"><A HREF="#lbAW">Background Commands -- &</A><DD>
|
|
<DT id="234"><A HREF="#lbAX">Lists -- Generally Speaking</A><DD>
|
|
<DT id="235"><A HREF="#lbAY">Short-Circuit List Operators</A><DD>
|
|
<DT id="236"><A HREF="#lbAZ">Flow-Control Constructs -- if, while, for, case</A><DD>
|
|
<DT id="237"><A HREF="#lbBA">Grouping Commands Together</A><DD>
|
|
<DT id="238"><A HREF="#lbBB">Functions</A><DD>
|
|
<DT id="239"><A HREF="#lbBC">Variables and Parameters</A><DD>
|
|
<DT id="240"><A HREF="#lbBD">Positional Parameters</A><DD>
|
|
<DT id="241"><A HREF="#lbBE">Special Parameters</A><DD>
|
|
<DT id="242"><A HREF="#lbBF">Word Expansions</A><DD>
|
|
<DT id="243"><A HREF="#lbBG">Tilde Expansion (substituting a user's home directory)</A><DD>
|
|
<DT id="244"><A HREF="#lbBH">Parameter Expansion</A><DD>
|
|
<DT id="245"><A HREF="#lbBI">Command Substitution</A><DD>
|
|
<DT id="246"><A HREF="#lbBJ">Arithmetic Expansion</A><DD>
|
|
<DT id="247"><A HREF="#lbBK">White Space Splitting (Field Splitting)</A><DD>
|
|
<DT id="248"><A HREF="#lbBL">Pathname Expansion (File Name Generation)</A><DD>
|
|
<DT id="249"><A HREF="#lbBM">Shell Patterns</A><DD>
|
|
<DT id="250"><A HREF="#lbBN">Builtins</A><DD>
|
|
<DT id="251"><A HREF="#lbBO">Command Line Editing</A><DD>
|
|
</DL>
|
|
<DT id="252"><A HREF="#lbBP">EXIT STATUS</A><DD>
|
|
<DT id="253"><A HREF="#lbBQ">ENVIRONMENT</A><DD>
|
|
<DT id="254"><A HREF="#lbBR">FILES</A><DD>
|
|
<DT id="255"><A HREF="#lbBS">SEE ALSO</A><DD>
|
|
<DT id="256"><A HREF="#lbBT">HISTORY</A><DD>
|
|
<DT id="257"><A HREF="#lbBU">BUGS</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:09 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|