?? _chapter 9.htm
字號(hào):
<p class="docList">The alias for the <span class="docEmphasis">more</span>
command is set to <span class="docEmphasis">mroe.</span> This is handy if
you can't spell.</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The alias definition is enclosed in quotes because of
the whitespace. The alias <span class="docEmphasis">lF</span> is a
nickname for the command <span class="docEmphasis">ls 朼lF.</span></span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">When <span class="docEmphasis">cd</span> is executed,
the alias for <span class="docEmphasis">cd</span> will cause
<span class="docEmphasis">cd</span> to go to the directory named as an
argument and will then reset the prompt to the current working directory
followed by the string <span class="docEmphasis">>.</span> The
<span class="docEmphasis">!*</span> is used by the alias in the same way
it is used by the history mechanism. The backslash prevents the history
mechanism from evaluating the <span class="docEmphasis">!*</span> first
before the alias has a chance to use it. The <span class="docEmphasis">\!*</span>
represents the arguments from the most recent command on the history list.</span></li>
</ol>
</span></td>
</tr>
</table>
<p class="docText"><b>Deleting Aliases.</b> The <span class="docEmphasis">
unalias</span> command is used to delete an alias. To temporarily turn off an
alias, the alias name is preceded by a backslash.</p>
<h5 id="ch09list22" class="docExampleTitle">Example 9.22 </h5>
<pre>1 % <span class="docEmphStrong">unalias mroe</span>
2 % <span class="docEmphStrong">\cd ..</span>
</pre>
<table cellSpacing="0" width="90%" border="1" align="center">
<tr>
<td>
<h2 class="docSidebarTitle">EXPLANATION</h2>
<span style="FONT-WEIGHT: bold">
<ol class="docList" type="1">
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The <span class="docEmphasis">unalias</span> command
deletes the alias <span class="docEmphasis">mroe</span> from the list of
defined aliases.</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The alias <span class="docEmphasis">cd</span> is
temporarily turned off for this execution of the command only.</span></li>
</ol>
</span></td>
</tr>
</table>
<p class="docText"><b>Alias Loop.</b> An alias loop occurs when an alias
definition references another alias that references back to the original alias.</p>
<h5 id="ch09list23" class="docExampleTitle">Example 9.23 </h5>
<pre>1 % alias m more
2 % alias mroe m
3 % alias m mroe <span class="docEmphasis"># Causes a loop</span>
4 % <span class="docEmphStrong">m datafile</span>
<span class="docEmphasis">Alias loop.</span>
</pre>
<table cellSpacing="0" width="90%" border="1" align="center">
<tr>
<td>
<h2 class="docSidebarTitle">EXPLANATION</h2>
<span style="FONT-WEIGHT: bold">
<ol class="docList" type="1">
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The alias is <span class="docEmphasis">m.</span> The
alias definition is <span class="docEmphasis">more.</span> Every time
<span class="docEmphasis">m</span> is used, the <span class="docEmphasis">
more</span> command is executed.</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The alias is <span class="docEmphasis">mroe.</span> The
alias definition is <span class="docEmphasis">m.</span> If
<span class="docEmphasis">mroe</span> is typed, the alias
<span class="docEmphasis">m</span> is invoked and the
<span class="docEmphasis">more</span> command is executed.</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">This is the culprit. If alias <span class="docEmphasis">
m</span> is used, it invokes alias <span class="docEmphasis">mroe,</span>
and alias <span class="docEmphasis">mroe</span> references back to
<span class="docEmphasis">m,</span> causing an alias loop. Nothing bad
happens. You just get an error message.</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">Alias <span class="docEmphasis">m</span> is used. It is
circular. <span class="docEmphasis">M</span> calls
<span class="docEmphasis">mroe</span> and <span class="docEmphasis">mroe</span>
calls <span class="docEmphasis">m,</span> then <span class="docEmphasis">m</span>
calls <span class="docEmphasis">mroe,</span> etc., etc. Rather than
looping forever, the C shell catches the problem and displays an error
message.</span></li>
</ol>
</span></td>
</tr>
</table>
<h4 class="docSection2Title" id="ch09lev2sec6">9.1.6 Job Control</h4>
<p class="docText">Job control is a powerful feature of the C shell that allows
you to run programs, called <span class="docEmphasis">jobs,</span> in the
background or foreground. Normally, a command typed at the command line runs in
the foreground, and will continue until it has finished. If you have windows,
job control may not be necessary, since you can simply open another window to
start a new task. On the other hand, with a single terminal, job control is a
very useful feature. For a list of job commands, see
<a class="docLink" href="#ch09table01">Table 9.1</a>.</p>
<table cellSpacing="0" cellPadding="1" width="100%" border="1">
<caption>
<h5 id="ch09table01" class="docTableTitle">Table 9.1. Job Control Commands</h5>
</caption>
<colgroup span="2" align="left">
</colgroup>
<tr>
<th class="docTableHeader" vAlign="top"><span class="docEmphBoldItalic">
Command</span> </th>
<th class="docTableHeader" vAlign="top"><span class="docEmphBoldItalic">
Meaning</span> </th>
</tr>
<tr>
<td class="docTableCell" vAlign="top"><span class="docEmphasis">jobs</span>
</td>
<td class="docTableCell" vAlign="top">Lists all the jobs running. </td>
</tr>
<tr>
<td class="docTableCell" vAlign="top">^Z (Control-Z) </td>
<td class="docTableCell" vAlign="top">Stops (suspends) the job; the prompt
appears on the screen. </td>
</tr>
<tr>
<td class="docTableCell" vAlign="top"><span class="docEmphasis">bg</span>
</td>
<td class="docTableCell" vAlign="top">Starts running the stopped job in the
background. </td>
</tr>
<tr>
<td class="docTableCell" vAlign="top"><span class="docEmphasis">fg</span>
</td>
<td class="docTableCell" vAlign="top">Brings a background job to the
foreground. </td>
</tr>
<tr>
<td class="docTableCell" vAlign="top"><span class="docEmphasis">kill</span>
</td>
<td class="docTableCell" vAlign="top">Sends the <span class="docEmphasis">
kill</span> signal to a specified job. </td>
</tr>
</table>
<p class="docText"><b>The Ampersand and Background Jobs.</b> If you expect a
command to take a long time to complete, you can append the command with an
ampersand and the job will execute in the background. The C shell prompt returns
immediately and now you can type another command. Now the two commands are
running concurrently, one in the background and one in the foreground. They both
send their standard output to the screen. If you place a job in the background,
it is a good idea to redirect its output either to a file or pipe it to a device
such as a printer.</p>
<h5 id="ch09list24" class="docExampleTitle">Example 9.24 </h5>
<pre>1 % <span class="docEmphStrong">find . -name core -exec rm {} \; &</span>
2 <span class="docEmphasis">[1] 543</span>
3 %
</pre>
<table cellSpacing="0" width="90%" border="1" align="center">
<tr>
<td>
<h2 class="docSidebarTitle">EXPLANATION</h2>
<span style="FONT-WEIGHT: bold">
<ol class="docList" type="1">
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The <span class="docEmphasis">find</span> command runs
in the background. (Without the <span class="docEmphasis">杙rint</span>
option, the <span class="docEmphasis">find</span> command does not send
any output to the screen).<span id="ENB9-3"><a class="docLink" href="#EN9-3"><sup>[3]</sup></a></span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The number in square brackets indicates this is the
first job to be run in the background and the PID for this process is
<span class="docEmphasis">543.</span></span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The prompt returns immediately. The shell waits for
user input.</span></li>
</ol>
</span></td>
</tr>
</table>
<p class="docText"><b>The Suspend Key Sequence and Background Jobs.</b> To
suspend a program, the suspend key sequence, ^Z, is issued. The job is now
suspended (stopped), the shell prompt is displayed, and the program will not
resume until the <span class="docEmphasis">fg</span> or
<span class="docEmphasis">bg</span> commands are issued. (When using the
<span class="docEmphasis">vi</span> editor, the <span class="docEmphasis">ZZ</span>
command writes and saves a file. Do not confuse this with ^Z, which would
suspend the <span class="docEmphasis">vi</span> session.) If you try to log out
when a job is suspended, the message <span class="docEmphasis">There are stopped
jobs</span> appears on the screen.</p>
<p class="docText"><span class="docEmphStrong">The <span class="docEmphasis">
jobs</span> Command.</span> The C shell built-in command,
<span class="docEmphasis">jobs,</span> displays the programs that are currently
active and either running or suspended in the background.
<span class="docEmphasis">Running</span> means the job is executing in the
background. When a job is <span class="docEmphasis">stopped,</span> it is
suspended; it is not in execution. In both cases, the terminal is free to accept
other commands.</p>
<h5 id="ch09list25" class="docExampleTitle">Example 9.25 </h5>
<pre>(The Command Line)
1 % <span class="docEmphStrong">jobs</span>
2 <span class="docEmphasis">[1] + Stopped vi filex</span>
<span class="docEmphasis">[2] - Running sleep 25</span>
3 % <span class="docEmphStrong">jobs -l</span>
<span class="docEmphasis">[1] + 355 Stopped vi filex</span>
<span class="docEmphasis">[2] - 356 Running sleep 25</span>
4 <span class="docEmphasis">[2] Done sleep 25</span>
</pre>
<table cellSpacing="0" width="90%" border="1" align="center">
<tr>
<td>
<h2 class="docSidebarTitle">EXPLANATION</h2>
<span style="FONT-WEIGHT: bold">
<ol class="docList" type="1">
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The <span class="docEmphasis">jobs</span> command lists
the currently active jobs.</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The notation <span class="docEmphasis">[1]</span> is
the number of the first job; the plus sign indicates that the job is not
the most recent job to be placed in the background; the dash indicates
that this is the most recent job put in the background;
<span class="docEmphasis">Stopped</span> means that this job was suspended
with ^Z and is not currently active.</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">The <span class="docEmphasis">杔</span> option (long
listing) displays the number of the job as well as the PID of the job. The
notation <span class="docEmphasis">[2]</span> is the number of the second
job, in this case, the last job placed in the background. The dash
indicates that this is the most recent job. The <span class="docEmphasis">
sleep</span> command is running in the background.</span></li>
<li><span style="FONT-WEIGHT: normal">
<p class="docList">After <span class="docEmphasis">sleep</span> has been
running for <span class="docEmphasis">25</span> seconds, the job will
complete and a message saying that it
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -