home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
gnu
/
man
/
cat1
/
sh.0
< prev
next >
Wrap
Text File
|
1993-12-08
|
41KB
|
782 lines
sh(C) 06 January 1993 sh(C)
_N_a_m_e
sh - invoke the shell command interpreter
_S_y_n_t_a_x
sshh [ --aacceeiikknnrrssttuuvvxx ] [ _aa_rr_gg_ss ]
_D_e_s_c_r_i_p_t_i_o_n
The shell is the standard command programming language that executes com-
mands read from a terminal or a file. See ``Invocation'' below for the
meaning of arguments to the shell.
_C_o_m_m_a_n_d_s
A _s_i_m_p_l_e-_c_o_m_m_a_n_d is a sequence of nonblank _w_o_r_d_s separated by _b_l_a_n_k_s (a
_b_l_a_n_k is a tab or a space). The first word specifies the name of the
command to be executed. Except as specified below, the remaining words
are passed as arguments to the invoked command. The command name is
passed as argument 0 (see eexxeecc(S)). The _v_a_l_u_e of a simple-command is its
exit status if it terminates normally, or (octal) 1000+_ss_tt_aa_tt_uu_ss if it ter-
minates abnormally. See ssiiggnnaall(S) for a list of status values.
A _p_i_p_e_l_i_n_e is a sequence of one or more _c_o_m_m_a_n_d_s separated by a vertical
bar (||). (The caret (^^), is an obsolete synonym for the vertical bar and
should not be used in a pipeline. Scripts that use ``^'' for pipelines
are incompatible with the Korn shell.) The standard output of each com-
mand but the last is connected by a ppiippee(S) to the standard input of the
next command. Each command is run as a separate process; the shell waits
for the last command to terminate.
A _l_i_s_t is a sequence of one or more pipelines separated by ;;, &&, &&&&, or
||||, and optionally terminated by ;; or &&. Of these four symbols, ;; and &&
have equal precedence, which is lower than that of &&&& and ||||. The sym-
bols &&&& and |||| also have equal precedence. A semicolon (;;) causes
sequential execution of the preceding pipeline; an ampersand (&&) causes
asynchronous execution of the preceding pipeline (that is, the shell does
_n_o_t wait for that pipeline to finish). The symbol &&&& (||||) causes the
_l_i_s_t following it to be executed only if the preceding pipeline returns a
zero (nonzero) exit status. An arbitrary number of newlines may appear
in a _l_i_s_t, instead of semicolons, to delimit commands.
A _c_o_m_m_a_n_d is either a simple-command or one of the following commands.
Unless otherwise stated, the value returned by a command is that of the
last simple-command executed in the command:
ffoorr _nn_aa_mm_ee [ iinn _ww_oo_rr_dd ... ]
ddoo
_ll_ii_ss_tt
ddoonnee
Each time a ffoorr command is executed, _nn_aa_mm_ee is set to the next _ww_oo_rr_dd taken
from the iinn _ww_oo_rr_dd list. If iinn _ww_oo_rr_dd is omitted, then the ffoorr command exe-
cutes the ddoo _ll_ii_ss_tt once for each positional parameter that is set (see
``Parameter substitution'' below). Execution ends when there are no more
words in the list.
ccaassee _ww_oo_rr_dd iinn
[ _pp_aa_tt_tt_ee_rr_nn [ | _pp_aa_tt_tt_ee_rr_nn ] ... )) _ll_ii_ss_tt
;;;; ]
eessaacc
A ccaassee command executes the _ll_ii_ss_tt associated with the first _pp_aa_tt_tt_ee_rr_nn that
matches _ww_oo_rr_dd. The form of the patterns is the same as that used for
filename generation (see ``Filename generation'' below).
iiff _ll_ii_ss_tt
tthheenn
_ll_ii_ss_tt
[ eelliiff _ll_ii_ss_tt tthheenn
_ll_ii_ss_tt ]
...
[ eellssee _ll_ii_ss_tt ]
ffii
The _ll_ii_ss_tt following iiff is executed and, if it returns a zero exit status,
the _ll_ii_ss_tt following the first tthheenn is executed. Otherwise, the _ll_ii_ss_tt fol-
lowing eelliiff is executed and, if its value is zero, the _ll_ii_ss_tt following the
next tthheenn is executed. Failing that, the eellssee _ll_ii_ss_tt is executed. If no
eellssee _ll_ii_ss_tt or tthheenn _ll_ii_ss_tt is executed, then the iiff command returns a zero
exit status.
wwhhiillee _ll_ii_ss_tt
ddoo
_ll_ii_ss_tt
ddoonnee
A wwhhiillee command repeatedly executes the wwhhiillee _ll_ii_ss_tt and, if the exit
status of the last command in the list is zero, executes the ddoo _ll_ii_ss_tt;
otherwise the loop terminates. If no commands in the ddoo _ll_ii_ss_tt are exe-
cuted, then the wwhhiillee command returns a zero exit status; uunnttiill may be
used in place of wwhhiillee to negate the loop termination test.
uunnttiill _ll_ii_ss_tt
ddoo
_ll_ii_ss_tt
ddoonnee
uunnttiill is similar to wwhhiillee, only uunnttiill continues execution until the first
_ll_ii_ss_tt returns a zero exit status. In other words, uunnttiill works until the
test condition succeeds (it works the whole time the command is failing);
wwhhiillee works until the test condition fails. uunnttiill is useful when you are
waiting for a particular event to occur.
((_ll_ii_ss_tt))
Executes _ll_ii_ss_tt in a subshell.
{{_ll_ii_ss_tt;;}}
_ll_ii_ss_tt is simply executed.
_nn_aa_mm_ee (()) {{_ll_ii_ss_tt;;}}
Define a function which is referenced by _nn_aa_mm_ee. The body of functions is
the _ll_ii_ss_tt of commands between {{ and }}. Execution of functions is
described later (see ``Execution''.)
The following words are recognized only as the first word of a command
and when not quoted:
iiff tthheenn eellssee eelliiff ffii ccaassee eessaacc
ffoorr wwhhiillee uunnttiill ddoo ddoonnee {{ }}
_C_o_m_m_e_n_t_s
A word beginning with ## causes that word and all the following characters
up to a newline to be ignored.
_C_o_m_m_a_n_d _s_u_b_s_t_i_t_u_t_i_o_n
The standard output from a command enclosed between grave accents ( `` `` )
may be used as part or all of a word; trailing newlines are removed.
No interpretation is done on the command string before the string is
read, except to remove backslashes (\\) used to escape other characters.
Backslashes may be used to escape grave accents (``) or other backslashes
and are removed before the command string is read. Escaping grave
accents allows nested command substitution. If the command substitution
lies within a pair of double quotes ( "" `` ...... `` "" ), backslashes used to
escape a double quote (\\"") will be removed; otherwise, they will be left
intact.
If a backslash is used to escape a newline character, both the backslash
and the newline are removed (see the section on ``Quoting''). In addi-
tion, backslashes used to escape dollar signs ( \\$$ ) are removed. Since
no interpretation is done on the command string before it is read,
inserting a backslash to escape a dollar sign has no effect. Backslashes
that precede characters other than \\, ``, "", nneewwlliinnee, and $$ are left
intact.
_P_a_r_a_m_e_t_e_r _s_u_b_s_t_i_t_u_t_i_o_n
The character $$ is used to introduce substitutable _p_a_r_a_m_e_t_e_r_s. There are
two types of parameters, positional and keyword. If _p_a_r_a_m_e_t_e_r is a
digit, it is a positional parameter. Positional paramete