⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch05_08.htm

📁 unix基础教程
💻 HTM
📖 第 1 页 / 共 4 页
字号:
% <tt class="userinput"><b>eval echo $b</b></tt>    <i class="lineannotation">Read the command line twice</i>hello</pre></blockquote></td></tr><tr><td valign="top"><a name="exec">exec</a></a></td><td><tt class="literal">exec</tt> <em class="replaceable"><tt>command</tt></em><p><a name="IXT-5-123050" />Execute <em class="emphasis">command</em> in place of current shell.This terminates the current shell, rather than creatinga new process under it.</p></td></tr><tr><td valign="top"><a name="exit">exit</a></a></td><td><tt class="literal">exit</tt> [<tt class="literal">(</tt><em class="replaceable"><tt>expr</tt></em><tt class="literal">)</tt>]<p><a name="IXT-5-123051" />Exit a shell script with the status given by <em class="emphasis">expr</em>.  A status of 0means success; nonzero means failure.  If <em class="emphasis">expr</em> is not specified,the exit value is that of the <tt class="literal">status</tt> variable.<tt class="literal">exit</tt> can be issued at the command line to close a window (log out).</p></td></tr><tr><td valign="top"><a name="fg">fg</a></a></td><td><tt class="literal">fg</tt> [<em class="replaceable"><tt>jobIDs</tt></em>]<p><a name="IXT-5-123052" />Bring the current job or the <em class="emphasis">jobIDs</em> to the foreground.  See also <a href="ch05_06.htm#unut-ch-5-sect-6">Section 5.6</a> earlier in this chapter.</p><h4 class="refsect2">Example</h4><p>If you suspend a <tt class="literal">vi</tt> editing session (by pressing <tt class="literal">CTRL-Z</tt>),you might resume <tt class="literal">vi</tt> using any of these commands:</p><blockquote><pre class="code">8% <tt class="userinput"><b>%</b></tt>8% <tt class="userinput"><b>fg</b></tt>8% <tt class="userinput"><b>fg %</b></tt>8% <tt class="userinput"><b>fg %vi</b></tt>    <i class="lineannotation">Match initial string</i></pre></blockquote></td></tr><tr><td valign="top"><a name="foreach">foreach</a></a></td><td><tt class="literal">foreach</tt> <em class="replaceable"><tt>name</em> <tt class="literal">(</tt><em class="replaceable">wordlist</em><tt class="literal">)</tt><br>&#160;&#160;&#160;&#160;&#160;<em class="replaceable">commands</tt></em><br><tt class="literal">end</tt><p><a name="IXT-5-123053" />Assign variable <em class="emphasis">name</em> to each value in <em class="emphasis">wordlist</em>, andexecute <em class="emphasis">commands</em> between <tt class="literal">foreach</tt> and <tt class="literal">end</tt>.You can use <tt class="literal">foreach</tt> as a multiline commandissued at the C shell prompt (first Example),or you can use it in a shell script (second Example).</p><h4 class="refsect2">Examples</h4><p>Rename all files that begin with a capital letter:</p><blockquote><pre class="code">% <tt class="userinput"><b>foreach i ([A-Z]*)</b></tt>? <tt class="userinput"><b>mv $i $i.new</b></tt>? <tt class="userinput"><b>end</b></tt></pre></blockquote><p>Check whether each command-line argument is an option or not:</p><blockquote><pre class="code">foreach arg ($argv)   # does it begin with - ?   if ("$arg" =~ -*) then      echo "Argument is an option"   else      echo "Argument is a filename"   endifend</pre></blockquote></td></tr><tr><td valign="top"><a name="glob">glob</a></a></td><td><tt class="literal">glob</tt> <em class="replaceable"><tt>wordlist</tt></em><p><a name="IXT-5-123054" />Do filename, variable, and history substitutions on <em class="emphasis">wordlist</em>.This expands it much like <tt class="literal">echo</tt>, except that no \ escapes are recognized, and words are delimited by null characters.<tt class="literal">glob</tt> is typically used in shell scripts to &#8220;hardcode&#8221; a valueso that it remains the same for the rest of the script.</p></td></tr><tr><td valign="top"><a name="goto">goto</a></a></td><td><tt class="literal">goto</tt> <em class="replaceable"><tt>string</tt></em><p><a name="IXT-5-123055" />Skip to a line whose first nonblank character is <em class="emphasis">string</em>followed by a <tt class="literal">:</tt>, and continue execution below that line.On the <tt class="literal">goto</tt> line, <em class="emphasis">string</em> can be a variable or filename pattern,but the label branched to must be a literal, expanded valueand must not occur within a <tt class="literal">foreach</tt> or <tt class="literal">while</tt>.</p></td></tr><tr><td valign="top"><a name="hashstat">hashstat</a></a></td><td><tt class="literal">hashstat</tt><p><a name="IXT-5-123056" />Display statistics that show the hash table's level of success at locatingcommands via the <tt class="literal">path</tt> variable.</p></td></tr><tr><td valign="top"><a name="history">history</a></a></td><td><tt class="literal">history</tt> [<em class="replaceable"><tt>options</tt></em>]<p><a name="IXT-5-123057" />Display the list of history events.  (History syntax is discussedearlier in <a href="ch05_05.htm#unut-ch-5-sect-5">Section 5.5</a>.)</p><p>Note: multiline compound commands such as <tt class="literal">foreach ... end</tt>are <em class="emphasis">not</em> saved in the history list.</p><h4 class="refsect2">Options</h4><dl><dt><tt class="literal">-h</tt></dt><dd>Print history list without event numbers.</p></dd><dt><tt class="literal">-r</tt></dt><dd>Print in reverse order; show oldest commands last.</p></dd><dt><i><tt><em class="replaceable"><tt>n</em></tt></i></dt><dd>Display only the last <em class="emphasis">n</tt></em></tt> history commands, insteadof the number set by the <tt class="literal">history</tt> shell variable.</p></dd></dl><h4 class="refsect2">Example</h4><p>To save and execute the last five commands:</p><blockquote><pre class="code">history -h 5 &gt; do_itsource do_it</pre></blockquote></td></tr><tr><td valign="top"><a name="if">if</a></a></td><td><tt class="literal">if</tt><p><a name="IXT-5-123058" />Begin a conditional statement.  The simple format is:</p><blockquote><pre class="code">if (<tt><em class="replaceable"><tt>expr</em></tt>) <tt><em class="replaceable">cmd</tt></em></tt></pre></blockquote><p>There are three other possible formats, shown side-by-side:</p><blockquote><pre class="code">if (<tt><em class="replaceable"><tt>expr</em></tt>) then   if (<tt><em class="replaceable">expr</em></tt>) then   if (<tt><em class="replaceable">expr</tt></em></tt>) then   <tt><em class="replaceable"><tt>cmds</em></tt>             <tt><em class="replaceable">cmds1</em></tt>             <tt><em class="replaceable">cmds1</tt></em></tt>endif            else              else if (<tt><em class="replaceable"><tt>expr</tt></em></tt>) then                    <tt><em class="replaceable"><tt>cmds2</em></tt>             <tt><em class="replaceable">cmds2</tt></em></tt>                 endif             else                                      <tt><em class="replaceable"><tt>cmds3</tt></em></tt>                                   endif</pre></blockquote><p>In the simplest form, execute <em class="emphasis">cmd</em></tt> if <em class="emphasis">expr</em></tt> is true;otherwise, do nothing (redirection still occurs; this is a bug).  In the other forms, execute one or more commands.If <em class="emphasis">expr</em></tt> is true, continue with the commands after <tt class="literal">then</tt>;if <em class="emphasis">expr</em></tt> is false, branch to the commands after <tt class="literal">else</tt>(or after the <tt class="literal">else if</tt> and continue checking).For more examples, see <a href="ch05_04.htm#unut-ch-5-sect-4">Section 5.4</a> or <b class="emphasis-bold"><a href="#shift">shift</a></b> or <b class="emphasis-bold"><a href="#while">while</a></b>.</p><h4 class="refsect2">Example</h4><p>Take a default action if no command-line arguments are given:</p><blockquote><pre class="code">if ($#argv == 0) then   echo "No filename given.  Sending to Report."   set outfile = Reportelse   set outfile = $argv[1]endif</pre></blockquote></td></tr><tr><td valign="top"><a name="jobs">jobs</a></a></td><td><tt class="literal">jobs</tt> [<tt class="literal">-l</tt>]<p><a name="IXT-5-123059" />List all running or stopped jobs; <tt class="literal">-l</tt> includes process IDs.For example, you can check whether a long compilation or text formatis still running.  Also useful before logging out.</p></td></tr><tr><td valign="top"><a name="kill">kill</a></a></td><td><tt class="literal">kill</tt> [<tt><em class="replaceable"><tt>options</em></tt>] <tt><em class="replaceable">ID</tt></em></tt><p><a name="IXT-5-123060" />Terminate each specified process <em class="emphasis">ID</em></tt> or job <em class="emphasis">ID</em></tt>.You must own the process or be a privileged user.This built-in is similar to <tt class="literal">/usr/bin/kill</tt>described in <a href="ch02_01.htm">Chapter 2</a> but also allows symbolic job names.Stubborn processes can be killed using signal 9.  See also the earliersection&#8220;Job Control.&#8221;</p><h4 class="refsect2">Options</h4><dl><dt><tt class="literal">-l</tt></dt><dd>List the signal names.  (Used by itself.)</p></dd><dt><tt class="literal">-</tt><tt><em class="replaceable">signal</em></tt></dt><dd>The signal number(from <tt class="literal">/usr/include/sys/signal.h</tt>)or name (from <tt class="literal">kill -l</tt>).With a signal number of 9, the kill is absolute.</p></dd></dl><h4 class="refsect2">Signals</h4><p>Signals are definedin <tt class="literal">/usr/include/sys/signal.h</tt> and are listed here withoutthe <tt class="literal">SIG</tt> prefix.You probably have more signals on your system than theones shown here.</p><blockquote><pre class="code">HUP     1       hangupINT     2       interruptQUIT    3       quitILL     4       illegal instructionTRAP    5       trace trapIOT     6       IOT instructionEMT     7       EMT instructionFPE     8       floating point exceptionKILL    9       killBUS     10      bus errorSEGV    11      segmentation violationSYS     12      bad argument to system callPIPE    13      write to pipe, but no process to read itALRM    14      alarm clockTERM    15      software termination (the default signal)USR1    16      user-defined signal 1USR2    17      user-defined signal 2CLD     18      child process diedPWR     19      restart after power failure</pre></blockquote><h4 class="refsect2">Examples</h4><p>If you've issued the following command:</p><blockquote><pre class="code">44% <tt class="userinput"><b>nroff -ms report &gt; report.txt &amp;</b></tt>[1] 19536               <i class="lineannotation">csh prints job and process IDs</i></pre></blockquote><p>you can terminate it in any of the following ways:</p><blockquote><pre class="code">45% <tt class="userinput"><b>kill 19536</b></tt>            <i class="lineannotation">Process ID</i>45% <tt class="userinput"><b>kill %</b></tt>                <i class="lineannotation">Current job</i>45% <tt class="userinput"><b>kill %1</b></tt>               <i class="lineannotation">Job number 1</i>45% <tt class="userinput"><b>kill %nr</b></tt>              <i class="lineannotation">Initial string</i>45% <tt class="userinput"><b>kill %?report</b></tt>         <i class="lineannotation">Matching string</i></pre></blockquote></td></tr><tr><td valign="top"><a name="limit">limit</a></a></td><td><tt class="literal">limit</tt> [<tt class="literal">-h</tt>] [<tt><em class="replaceable"><tt>resource</em></tt> [<tt><em class="replaceable">limit</tt></em></tt>]]<p><a name="IXT-5-123061" />Display limits or set a <em class="emphasis">limit</em></tt> on resources used by the current process and by eachprocess it creates. If no <em class="emphasis">limit</em></tt> is given, the current limit is printed for<em class="emphasis">resource</em></tt>. If <em class="emphasis">resource</em></tt> is also omitted, all limits are printed.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -