<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<!-- Copyright 1997 The Open Group, All Rights Reserved -->
<title>Shell Command Language</title>
</head><body bgcolor=white>
<center>
<font size=2>
The Single UNIX ® Specification, Version 2<br>
Copyright © 1997 The Open Group
</font></center>
<hr size=2 noshade><blockquote>
<center>
<h2><a name = "tag_001"> </a>Shell Command Language</h2>
</center>
<xref type="1" name="shell"></xref>
This chapter contains the definition of the
XSI Shell Command Language.
See the <a href ="shellix.html">Shell Command Language Index</a> for
an overview.
<h3><a name = "tag_001_001"> </a>Shell Introduction</h3>
The shell is a command language interpreter.
This chapter describes the syntax of that
command language as it is used by the
<i><a href="sh.html">sh</a></i>
utility and the
<i><a href="../xsh/system.html">system()</a></i>
and
<i><a href="../xsh/popen.html">popen()</a></i>
functions in the <b>XSH</b> specification.
<p>
The shell operates according to the following general overview
of operations.
The specific details are included in the cited sections
of this chapter.
<ol>
<p>
<li>
The shell reads its input from a file (see
<i><a href="sh.html">sh</a></i>),
from the
<b>-c</b>
option
or from the
<i><a href="../xsh/system.html">system()</a></i>
and
<i><a href="../xsh/popen.html">popen()</a></i>
functions in the <b>XSH</b> specification.
If the first line
of a file of shell commands starts with the characters
#!,
the results
are unspecified.
<p>
The construct
#!
is reserved for implementations wishing
to provide that extension.
A portable application cannot use
#!
as the first line of a shell script;
it might not be interpreted as a comment.
<p>
<li>
The shell breaks the input into tokens:
words and operators.
(See
<xref href=token><a href="#tag_001_003">
Token Recognition
</a></xref>.)
<p>
<li>
The shell parses the input into simple commands
(see
<xref href=simpcmd><a href="#tag_001_009_001">
Simple Commands
</a></xref>)
and compound commands
(see
<xref href=compcmd><a href="#tag_001_009_004">
Compound Commands
</a></xref>).
<p>
<li>
The shell performs various expansions
(separately) on different parts of each command, resulting in a
list of pathnames and fields to be treated as a command
and arguments (see
<xref href=wordexp><a href="#tag_001_006">
Word Expansions
</a></xref>).
<p>
<li>
The shell performs redirection (see
<xref href=redir><a href="#tag_001_007">
Redirection
</a></xref>)
and removes redirection operators and their operands from the
parameter list.
<p>
<li>
The shell executes a function (see
<xref href=funccmd><a href="#tag_001_009_005">
Function Definition Command
</a></xref>),
built-in (see
<xref href=sbi><a href="#tag_001_014">
Special Built-in Utilities
</a></xref>),
executable file or script, giving the
names of the arguments as positional
parameters numbered 1 to
<i>n</i>,
and the
name of the command (or in the case of
a function within a script, the name
of the script) as the positional
parameter numbered 0 (see
<xref href=cmdsea><a href="#tag_001_009_001_001">
Command Search and Execution
</a></xref>).
<p>
<li>
The shell optionally waits for the command to
complete and collects the exit status (see
<xref href=existat><a href="#tag_001_008_002">
Exit Status for Commands
</a></xref>).
<p>
</ol>
<hr size=2 noshade>
<h3><a name = "tag_001_002"> </a>Quoting</h3>
<xref type="2" name="quoting"></xref>
Quoting is used to remove the special meaning of certain
characters or words to the shell.
Quoting can be used to preserve
the literal meaning of
the special characters in the next paragraph; prevent reserved
words from being recognised as such; and prevent parameter expansion
and command substitution within here-document processing (see
<xref href=heredoc><a href="#tag_001_007_004">
Here-document
</a></xref>).
<p>
The following characters must be quoted if they are to
represent themselves:
<pre>
<code>
| & ; < > ( ) $ ` \ " ' <space> <tab> <newline>
</code>
</pre>
and the following may need to be quoted under certain circumstances.
That is, these characters may be special depending on
conditions described elsewhere in this specification:
<pre>
<code>
* ? [ # ~ = %
</code>
</pre>
<p>
The various quoting mechanisms are the escape character,
single-quotes and double-quotes.
The here-document represents another form of quoting; see
<xref href=heredoc><a href="#tag_001_007_004">
Here-document
</a></xref>.
<h4><a name = "tag_001_002_001"> </a>Escape Character (Backslash)</h4>
<xref type="3" name="esc"></xref>
A backslash that is not quoted
preserves the literal value of the following character,
with the exception of a
newline character.
If a
newline character
follows the
backslash,
the shell will interpret this as line continuation.
The backslash and
newline characters
will be removed before splitting the input into tokens.
Since the escaped
newline character
is removed entirely from the input
and is not replaced by any white space,
it cannot serve as a token separator.
<h4><a name = "tag_001_002_002"> </a>Single-quotes</h4>
Enclosing characters in single-quotes
(' ')
preserves the literal value of each character within the single-quotes.
A single-quote cannot occur within
single-quotes.
<p>
A backslash cannot be used to escape a single-quote
in a single-quoted string.
An embedded
quote can be created by writing, for example:
'a'\"b',
which yields
a'b.
(See
<xref href=fldspl><a href="#tag_001_006_005">
Field Splitting
</a></xref>
for a better understanding of how portions of words are either
split into fields or remain concatenated.)
A single token can be made up
of concatenated partial strings containing
all three kinds of quoting or escaping,
thus permitting any combination of characters.
<h4><a name = "tag_001_002_003"> </a>Double-quotes</h4>
<xref type="3" name="dquote"></xref>
Enclosing characters in double-quotes
(<b>" "</b>)
preserves the literal value of all characters within the double-quotes,
with the exception of the characters
dollar-sign, backquote and backslash, as follows:
<dl compact>
<dt>$<dd>The dollar-sign retains its special meaning introducing
parameter expansion (see
<xref href=parmexp><a href="#tag_001_006_002">
Parameter Expansion
</a></xref>),
a form of command substitution (see
<xref href=cmdsub><a href="#tag_001_006_003">
Command Substitution
</a></xref>),
and arithmetic expansion (see
<xref href=aritexp><a href="#tag_001_006_004">
Arithmetic Expansion
</a></xref>).
The input characters within the quoted string that are also enclosed
between "$(" and the matching "("
will not be affected by the
double-quotes, but rather
define that command whose output replaces the
$(...)
when the word is expanded.
The tokenising rules in
<xref href=token><a href="#tag_001_003">
Token Recognition
</a></xref>
are applied recursively to find the matching ")".
Within the string of characters from an enclosed
${
to the matching
"}",
an even number of
unescaped double-quotes or single-quotes, if any, must occur.
A preceding backslash character must be used to escape a literal
"{"
or
"}".
The rule in
<xref href=parmexp><a href="#tag_001_006_002">
Parameter Expansion
</a></xref>
will be used to determine the matching
"}".
<dt>`<dd>The backquote retains its special meaning introducing
the other form of command substitution (see
<xref href=cmdsub><a href="#tag_001_006_003">
Command Substitution
</a></xref>).
The portion of the quoted string from the initial backquote
and the characters up to the next backquote
that is not preceded by a backslash,
having escape characters removed,
defines that command whose output replaces `...`
when the word is expanded.
Either of the following cases produces undefined results:
<ul>
<li>
a single- or double-quoted string that begins, but does not end, within
the `...` sequence
<li>
a `...` sequence that begins, but does not end, within the
same doub
没有合适的资源?快使用搜索试试~ 我知道了~
susv2.rar_c 例程_susv
共1550个文件
html:1539个
gif:4个
htm:2个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 28 浏览量
2022-09-23
22:41:56
上传
评论
收藏 3.08MB RAR 举报
温馨提示
unix 下的C开发手册,还用详细的例程。
资源推荐
资源详情
资源评论
收起资源包目录
susv2.rar_c 例程_susv (1550个子文件)
Image11.gif 8KB
Image14.gif 6KB
Image12.gif 6KB
Image13.gif 5KB
cluster.htm 34KB
u018f.htm 9KB
chap2.html 169KB
locale.html 128KB
glossary.html 115KB
awk.html 88KB
vi.html 86KB
ex.html 81KB
terminfo.html 75KB
mailx.html 63KB
intov.html 52KB
pax.html 49KB
termios.html 48KB
sh.html 47KB
64bit.html 46KB
re.html 46KB
make.html 45KB
yacc.html 45KB
curses.h.html 41KB
xshix.html 40KB
sigaction.html 40KB
xti.h.html 39KB
bc.html 39KB
threads.html 38KB
ed.html 37KB
cluster.html 34KB
lex.html 33KB
ioctl.html 33KB
more.html 32KB
unistd.h.html 31KB
stty.html 29KB
ixfile.html 29KB
realtime.html 28KB
envvar.html 27KB
charset.html 26KB
c89.html 25KB
utildes.html 24KB
get.html 23KB
compilation.html 23KB
limits.h.html 22KB
cursesix.html 21KB
cc.html 21KB
t_optmgmt.html 21KB
sed.html 21KB
signal.h.html 20KB
od.html 20KB
sort.html 20KB
ls.html 19KB
fprintf.html 19KB
snprintf.html 19KB
errors.html 19KB
fscanf.html 19KB
fwscanf.html 19KB
at.html 19KB
fwprintf.html 19KB
utilconv.html 19KB
regexp.html 19KB
ipcs.html 18KB
ps.html 18KB
find.html 18KB
prs.html 18KB
dd.html 17KB
m4.html 17KB
is.html 17KB
xargs.html 17KB
execlp.html 17KB
execve.html 17KB
execl.html 17KB
execvp.html 17KB
execv.html 17KB
execle.html 17KB
exec.html 17KB
cp.html 17KB
lint.html 17KB
admin.html 16KB
date.html 16KB
diff.html 16KB
patch.html 16KB
ar.html 16KB
chmod.html 15KB
regfree.html 15KB
regexec.html 15KB
regcomp.html 15KB
regerror.html 15KB
stdio.html 15KB
printf.html 15KB
pg.html 15KB
write.html 15KB
writev.html 15KB
tr.html 15KB
test.html 14KB
mmap.html 14KB
read.html 14KB
fc.html 14KB
implement.html 14KB
pr.html 14KB
共 1550 条
- 1
- 2
- 3
- 4
- 5
- 6
- 16
资源评论
小贝德罗
- 粉丝: 71
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功