📄 project1.htm
字号:
have special meanings within the context of user input. These characters include
&, |, <, and >. Your shell can assume that these meta-characters
cannot occur inside strings representing programs, arguments, or files. Instead
they are reserved for use by the shell. The purpose of meta-characters is
discussed later in this section. </SPAN></P>
<P class=MsoNormal style="MARGIN-LEFT: 36pt"><SPAN lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<H4><SPAN lang=EN-US>Parsing User Input – Internal Commands</SPAN></H4>
<P class=MsoNormal style="MARGIN-LEFT: 36pt"><SPAN lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN-LEFT: 36pt"><SPAN lang=EN-US>If the command
line matches the format of an internal command as described earlier in this
document, it should be accepted as an internal command.<SPAN
style="mso-spacerun: yes"> </SPAN>If not, it should be considered to
specify the execution of external programs, or an error, as appropriate.
</SPAN></P>
<P class=MsoNormal><SPAN
lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><SPAN
style="mso-tab-count: 1">
</SPAN><B style="mso-bidi-font-weight: normal">Parsing User Input – Executing A
Single Program<o:p></o:p></B></SPAN></P>
<P class=MsoNormal><SPAN
lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN-LEFT: 36pt"><SPAN lang=EN-US>The execution of
a<SPAN style="mso-spacerun: yes"> </SPAN>program is specified by a
sequence of delimited strings. The first of these is the name of the executable
file that contains the desired program (modulo a search path as explained in the
</SPAN><SPAN class=HTMLTypewriter><SPAN lang=EN-US
style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-bidi-font-family: 黑体">execvp</SPAN></SPAN><SPAN
lang=EN-US> man page, see </SPAN><SPAN class=HTMLTypewriter><SPAN lang=EN-US
style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-bidi-font-family: 黑体">man
-s 2 execvp</SPAN></SPAN><SPAN lang=EN-US>) and the others are arguments passed
to the program. The command is an error if the executable file named by the
first string does not exist, or is not an executable. </SPAN></P>
<P class=MsoNormal style="MARGIN-LEFT: 36pt"><SPAN lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<H4><SPAN lang=EN-US>Paring User Input – I/O Redirection</SPAN></H4>
<P class=MsoNormal style="MARGIN-LEFT: 36pt"><SPAN lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN-LEFT: 36pt"><SPAN lang=EN-US>A program's
execution specified as above may be followed by the meta-character </SPAN><SPAN
lang=EN-US style="FONT-FAMILY: Symbol">< </SPAN><SPAN lang=EN-US><SPAN
style="mso-spacerun: yes"> </SPAN>or > which is in turn followed by a
file name. In the case of <, the input of the program will be redirected from
the specified file name. In the case of >, the output of the program will be
redirected to the specified file name. If the output file does not exist, it
should be created. If the input file does not exist, this is an
error.</SPAN></P>
<P class=MsoNormal style="MARGIN-LEFT: 36pt"><SPAN lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<H4><SPAN lang=EN-US>Parsing User Input – Pipes and Cooperating
Programs</SPAN></H4>
<P class=MsoNormal style="MARGIN-LEFT: 36pt"><SPAN lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN-LEFT: 36pt"><SPAN lang=EN-US>Several program
invocations can be present in a single command line, when separated by the shell
meta-character ``</SPAN><SPAN lang=EN-US
style="FONT-FAMILY: Symbol">|</SPAN><SPAN lang=EN-US>''. In this case, the shell
should fork all of them, chaining their outputs and inputs using pipes
appropriately. For instance, the command line </SPAN></P>
<P class=MsoNormal><SPAN class=HTMLTypewriter><SPAN lang=EN-US
style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-bidi-font-family: 黑体"><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></SPAN></P>
<P class=MsoNormal style="MARGIN-LEFT: 36pt; TEXT-INDENT: 36pt"><SPAN
class=HTMLTypewriter><SPAN lang=EN-US
style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-bidi-font-family: 黑体">progA
argA1 argA2 < infile </SPAN></SPAN><SPAN class=HTMLTypewriter><SPAN
lang=EN-US style="FONT-FAMILY: Symbol; FONT-SIZE: 10pt">|</SPAN></SPAN><SPAN
class=HTMLTypewriter><SPAN lang=EN-US
style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-bidi-font-family: 黑体">
progB argB1 > outfile</SPAN></SPAN><SPAN lang=EN-US> </SPAN></P>
<P class=MsoNormal><SPAN
lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN-LEFT: 36pt"><SPAN lang=EN-US>should fork
</SPAN><SPAN class=HTMLTypewriter><SPAN lang=EN-US
style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-bidi-font-family: 黑体">progA</SPAN></SPAN><SPAN
lang=EN-US> and </SPAN><SPAN class=HTMLTypewriter><SPAN lang=EN-US
style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-bidi-font-family: 黑体">progB</SPAN></SPAN><SPAN
lang=EN-US>, make the input for </SPAN><SPAN class=HTMLTypewriter><SPAN
lang=EN-US
style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-bidi-font-family: 黑体">progA</SPAN></SPAN><SPAN
lang=EN-US> come from file </SPAN><SPAN class=HTMLTypewriter><SPAN lang=EN-US
style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-bidi-font-family: 黑体">infile</SPAN></SPAN><SPAN
lang=EN-US>, the output from </SPAN><SPAN class=HTMLTypewriter><SPAN lang=EN-US
style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-bidi-font-family: 黑体">progA</SPAN></SPAN><SPAN
lang=EN-US> go to the input of </SPAN><SPAN class=HTMLTypewriter><SPAN
lang=EN-US
style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-bidi-font-family: 黑体">progB</SPAN></SPAN><SPAN
lang=EN-US>, and the output of </SPAN><SPAN class=HTMLTypewriter><SPAN
lang=EN-US
style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-bidi-font-family: 黑体">progB</SPAN></SPAN><SPAN
lang=EN-US> go to the file </SPAN><SPAN class=HTMLTypewriter><SPAN lang=EN-US
style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-bidi-font-family: 黑体">outfile</SPAN></SPAN><SPAN
lang=EN-US>. This should be accomplished using a pipe IPC primative. </SPAN></P>
<P class=MsoNormal style="MARGIN-LEFT: 36pt"><SPAN lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN-LEFT: 36pt"><SPAN lang=EN-US>A command line
with one or more ``pipes'' is an error if any of its component program
invocations is an error. A command line with ``pipes'' is an error if the input
of any but the first command is redirected, or if the output of any but the last
command is redirected. A job consisting of<SPAN style="mso-spacerun: yes">
</SPAN>piped processes is not considered to have completed until all of its
component processes have completed.</SPAN></P>
<P class=MsoNormal><SPAN
lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><SPAN
style="mso-tab-count: 1">
</SPAN><B style="mso-bidi-font-weight: normal">Parsing User Input – Background
Jobs<o:p></o:p></B></SPAN></P>
<P class=MsoNormal><SPAN
lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN-LEFT: 36pt"><SPAN lang=EN-US>The user can
specify that a job should be executed in the background by ending the command
line with the meta-character &. If this is the case, all program invocations
required by the command line are to be carried out in the background.
</SPAN></P>
<P class=MsoNormal style="MARGIN-LEFT: 36pt"><SPAN lang=EN-US><SPAN
style="mso-spacerun: yes"> </SPAN></SPAN></P>
<H5><A name=tth_sEc3.1></A><SPAN lang=EN-US>Parsing User Input – A
Grammar</SPAN></H5>
<P class=MsoNormal><SPAN
lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN-LEFT: 36pt"><SPAN lang=EN-US>The grammar below
provides a more formal description of the syntax governing user input. If you
are using lex/yacc to implement your parser, you’ll have to massage the grammar
slightly to make it LALR(1). This grammar doesn’t include the special
keystrokes, because they won’t show up in stdin as user input and should be
handled separately.</SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN-LEFT: 36pt"><SPAN lang=EN-US>A </SPAN><SPAN
class=HTMLTypewriter><SPAN lang=EN-US
style="FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt; mso-bidi-font-family: 黑体">CommandLine</SPAN></SPAN><SPAN
lang=EN-US> is legal input provided by the user, as a direction to the shell, in
response to the prompt. The grammar assumes that the existence of a lexical
analyzer that considers blank-space to be a delimiter, recognizes the
meta-characters as tokens, &c.</SPAN></P>
<P class=MsoNormal><SPAN
lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<P class=MsoNormal style="MARGIN-LEFT: 36pt"><!--[if gte vml 1]><v:shapetype
id=_x0000_t202 coordsize = "21600,21600" path =
"m0,0l0,21600,21600,21600,21600,0xe" o:spt = "202"><v:stroke joinstyle =
"miter"></v:stroke><v:path gradientshapeok = "t" o:connecttype =
"rect"></v:path></v:shapetype><v:shape id=_x0000_s1035
style="HEIGHT: 421.4pt; LEFT: 0px; MARGIN-LEFT: 0px; MARGIN-TOP: 3.4pt; POSITION: absolute; TEXT-ALIGN: left; WIDTH: 6in; Z-INDEX: 3; mso-position-horizontal: left"
type = "#_x0000_t202" coordsize = "21600,21600" o:allowincell = "f"><v:textbox><![if !mso]>
<TABLE cellPadding=0 cellSpacing=0 width="100%">
<TBODY>
<TR>
<TD><![endif]>
<DIV>
<P class=MsoNormal><SPAN lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
lang=EN-US>CommandLine := <SPAN
style="mso-tab-count: 1"> </SPAN>NULL</SPAN></P>
<P class=MsoNormal style="MARGIN-LEFT: 108pt; TEXT-INDENT: 36pt"><SPAN
lang=EN-US>FgCommandLine</SPAN></P>
<P class=MsoNormal style="MARGIN-LEFT: 108pt; TEXT-INDENT: 36pt"><SPAN
lang=EN-US>FgCommandLine &</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
lang=EN-US>FgCommandLine := <SPAN
style="mso-tab-count: 1"> </SPAN>SimpleCommand</SPAN></P>
<P class=MsoNormal style="MARGIN-LEFT: 108pt; TEXT-INDENT: 36pt"><SPAN
lang=EN-US>FirstCommand MidCommand LastCommand</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
lang=EN-US>SimpleCommand := <SPAN
style="mso-tab-count: 1"> </SPAN>ProgInvocation InputRedirect
OutputRedirect</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
lang=EN-US>FirstCommand := <SPAN
style="mso-tab-count: 1">
</SPAN>ProgInvocation InputRedirect</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
lang=EN-US>MidCommand :=<SPAN
style="mso-tab-count: 1">
</SPAN>NULL</SPAN></P>
<P class=MsoNormal><SPAN
lang=EN-US>
<SPAN
style="mso-tab-count: 3">
</SPAN>| ProgInvocation MidCommand</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
lang=EN-US>LastCommand := <SPAN
style="mso-tab-count: 1"> </SPAN>| ProgInvocation
OutputRedirect</SPAN></P>
<P class=MsoNormal><SPAN
lang=EN-US> </SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
lang=EN-US>ProgInvocation := <SPAN
style="mso-tab-count: 1">
</SPAN>ExecFile Args</SPAN></P>
<P class=MsoNormal><SPAN lang=EN-US><![if !supportEmptyParas]> <![endif]><o:p></o:p></SPAN></P>
<P class=MsoNormal style="TEXT-INDENT: 36pt"><SPAN
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -