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

📄 ch05_08.htm

📁 unix基础教程
💻 HTM
📖 第 1 页 / 共 4 页
字号:
<p><a name="IXT-5-123074" />If <em class="emphasis">variable</em> is given, shift the words in a word list variable;i.e., <em class="emphasis">name</em><tt class="literal">[2]</tt> becomes <em class="emphasis">name</em><tt class="literal">[1]</tt>.With no argument,shift the positional parameters (command-line arguments); i.e.,<tt class="literal">$2</tt> becomes <tt class="literal">$1</tt>.<tt class="literal">shift</tt> is typicallyused in a <tt class="literal">while</tt> loop.See additional Example under <b class="emphasis-bold"><a href="#while">while</a></b>.</p><h4 class="refsect2">Example</h4><blockquote><pre class="code">while ($#argv)      <i class="lineannotation">While there are arguments</i>    if (-f $argv[1])         wc -l $argv[1]    else       echo "$argv[1] is not a regular file"    endif    shift           <i class="lineannotation">Get the next argument</i>end</pre></blockquote></td></tr><tr><td valign="top"><a name="source">source</a></a></td><td><tt class="literal">source</tt> [<tt class="literal">-h</tt>] <em class="replaceable"><tt>script</tt></em><p><a name="IXT-5-123075" />Read and execute commands from a C shell script.  With <tt class="literal">-h</tt>, the commands areadded to the history list but aren't executed.</p><h4 class="refsect2">Example</h4><blockquote><pre class="code">source ~/.cshrc</pre></blockquote></td></tr><tr><td valign="top"><a name="stop">stop</a></a></td><td><p><tt class="literal">stop</tt> [<em class="replaceable"><tt>jobIDs</tt></em>]</p><p><a name="IXT-5-123076" />Suspend the current background job or thebackground job specified by <em class="emphasis">jobIDs</em>; this isthe complement of <tt class="literal">CTRL-Z</tt> or <tt class="literal">suspend</tt>.</p></td></tr><tr><td valign="top"><a name="suspend">suspend</a></a></td><td><tt class="literal">suspend</tt><p><a name="IXT-5-123077" />Suspend the current foreground job; similar to <tt class="literal">CTRL-Z</tt>.Often used to stop an <tt class="literal">su</tt> command.</p></td></tr><tr><td valign="top"><a name="switch">switch</a></a></td><td><tt class="literal">switch</tt><p><a name="IXT-5-123078" />Process commands depending on the value of a variable.When you need to handle more than three choices, <tt class="literal">switch</tt>is a useful alternative to an <tt class="literal">if-then-else</tt> statement.If the <em class="emphasis">string</em> variable matches <em class="emphasis">pattern1</em>,the first set of <em class="emphasis">commands</em> is executed; if <em class="emphasis">string</em> matches <em class="emphasis">pattern2</em>, the second set of <em class="emphasis">commands</em> is executed;and so on.  If no patterns match, execute commands under the<tt class="literal">default</tt> case.<em class="emphasis">string</em> can be specified using command substitution, variable substitution, or filename expansion.Patterns can be specified using pattern-matching symbols <tt class="literal">*</tt>, <tt class="literal">?</tt>, and <tt class="literal">[</tt> <tt class="literal">]</tt>.  <tt class="literal">breaksw</tt> exits the <tt class="literal">switch</tt> after <em class="emphasis">commands</em> are executed.  If <tt class="literal">breaksw</tt> is omitted (which is rarely done), the <tt class="literal">switch</tt> continues to execute another set of commands untilit reaches a <tt class="literal">breaksw</tt> or <tt class="literal">endsw</tt>.Here is the general syntax of <tt class="literal">switch</tt>, side-by-side with an examplethat processes the first command-line argument.  </p><blockquote><pre class="code">switch (<em class="replaceable"><tt>string</tt></em>)    switch ($argv[1])  case <em class="replaceable"><tt>pattern1</tt></em>:      case -[nN]:      <em class="replaceable"><tt>commands</tt></em>            nroff $file | lp      breaksw             breaksw  case <em class="replaceable"><tt>pattern2</tt></em>:      case -[Pp]:      <em class="replaceable"><tt>commands</tt></em>            pr $file | lp      breaksw             breaksw  case <em class="replaceable"><tt>pattern3</tt></em>:      case -[Mm]:      <em class="replaceable"><tt>commands</tt></em>            more $file      breaksw             breaksw      .                case -[Ss]:      .                    sort $file      .                    breaksw  default:             default:      <em class="replaceable"><tt>commands</tt></em>             echo "Error-no such option"                           exit 1      breaksw              breakswendsw                 endsw</pre></blockquote></td></tr><tr><td valign="top"><a name="time">time</a></a></td><td><p><tt class="literal">time</tt> [<em class="replaceable"><tt>command</tt></em>]</p><p><a name="IXT-5-123079" />Execute a <em class="emphasis">command</em> and show how much time it uses.With no argument, <tt class="literal">time</tt> can be used in a shell script to time it.</p></td></tr><tr><td valign="top"><a name="umask">umask</a></a></td><td><tt class="literal">umask</tt> [<em class="replaceable"><tt>nnn</tt></em>]<p><a name="IXT-5-123080" />Display file-creation mask or set file creation mask to octal<em class="emphasis">nnn</em>.  The file-creation mask determines which permission bitsare turned off.See theentry in <a href="ch02_01.htm">Chapter 2</a> for examples.</p></td></tr><tr><td valign="top"><a name="unalias">unalias</a></a></td><td><tt class="literal">unalias</tt> <em class="replaceable"><tt>name</tt></em><p><a name="IXT-5-123081" />Remove <em class="emphasis">name</em> from the alias list.See <b class="emphasis-bold"><a href="#alias">alias</a></b> for moreinformation.</p></td></tr><tr><td valign="top"><a name="unhash">unhash</a></a></td><td><tt class="literal">unhash</tt><p><a name="IXT-5-123082" />Remove internal hash table.  The C shell stops using hashed valuesand spends time searching the <tt class="literal">path</tt> directories to locate acommand.  See also <b class="emphasis-bold"><a href="#rehash">rehash</a></b>.</p></td></tr><tr><td valign="top"><a name="unlimit">unlimit</a></a></td><td><tt class="literal">unlimit</tt> [<em class="replaceable"><tt>resource</tt></em>]<p><a name="IXT-5-123083" />Remove the allocation limits on <em class="emphasis">resource</em>.  If <em class="emphasis">resource</em> is notspecified, remove limits for all resources.  See <b class="emphasis-bold"><a href="#limit">limit</a></b> for moreinformation.</p></td></tr><tr><td valign="top"><a name="unset">unset</a></a></td><td><tt class="literal">unset</tt> <em class="replaceable"><tt>variables</tt></em><p><a name="IXT-5-123084" />Remove one or more <em class="emphasis">variables</em>.  Variable names may be specifiedas a pattern, using filename metacharacters.  See <b class="emphasis-bold"><a href="#set">set</a></b>.</p></td></tr><tr><td valign="top"><a name="unsetenv">unsetenv</a></a></td><td><tt class="literal">unsetenv</tt> <em class="replaceable"><tt>variable</tt></em><p><a name="IXT-5-123085" />Remove an environment variable.  Filenamematching is <em class="emphasis">not</em> valid.See <b class="emphasis-bold"><a href="#setenv">setenv</a></b>.</p></td></tr><tr><td valign="top"><a name="wait">wait</a></a></td><td><p><tt class="literal">wait</tt></p><p><a name="IXT-5-123086" />Pause in execution until allbackground jobs complete,or until an interrupt signal is received.</p></td></tr><tr><td valign="top"><a name="while">while</a></a></td><td><p><tt class="literal">while (</tt><em class="replaceable"><tt>expression</em><tt class="literal">)</tt></p><p>&#160;&#160;&#160;&#160;&#160;<em class="replaceable">commands</tt></em></p><p><tt class="literal">end</tt></p><p><a name="IXT-5-123087" />As long as <em class="emphasis">expression</em> is true(evaluates to nonzero),evaluate <em class="emphasis">commands</em> between <tt class="literal">while</tt> and <tt class="literal">end</tt>.<tt class="literal">break</tt> and <tt class="literal">continue</tt> can terminate or continue the loop.See also the Example under <b class="emphasis-bold"><a href="#shift">shift</a></b>.</p><h4 class="refsect2">Example</h4><blockquote><pre class="code">set user = (alice bob carol ted)while ($argv[1] != $user[1])   <i class="lineannotation">Cycle through each user, checking for a match</i>   shift user   <i class="lineannotation">If we cycled through with no match...</i>   if ($#user == 0) then     echo "$argv[1] is not on the list of users"     exit 1   endifend</pre></blockquote></td></tr><tr><td valign="top"><a name="@">@</a></a></td><td><tt class="literal">@</tt> <em class="replaceable"><tt>variable</em> <tt class="literal">=</tt> <em class="replaceable">expression</em><br><tt class="literal">@</tt> <em class="replaceable">variable</em><tt class="literal">[</tt><em class="replaceable">n</em><tt class="literal">] =</tt> <em class="replaceable">expression</tt></em><br><tt class="literal">@</tt><p><a name="IXT-5-123088" />Assign the value of the arithmetic <em class="emphasis">expression</em> to <em class="emphasis">variable</em>, or to the <em class="emphasis">n</em>th element of <em class="emphasis">variable</em> if the index <em class="emphasis">n</em> is specified.  With no <em class="emphasis">variable</em> or <em class="emphasis">expression</em>specified, print the values of all shell variables (same as <tt class="literal">set</tt>).Expression operators as well as examples are listed in <a href="ch05_04.htm#unut-ch-5-sect-4">Section 5.4</a>.  Two special forms are also valid:</p><dl><dt><tt class="literal">@</tt> <tt><em class="replaceable">variable</em></tt><tt class="literal">++</tt></dt><dd>Increment <em class="emphasis">variable</em></tt> by one.</p></dd><dt><tt class="literal">@</tt> <tt><em class="replaceable">variable</em></tt><tt class="literal">--</tt></dt><dd>Decrement <em class="emphasis">variable</em></tt> by one.</p></dd></dl></td></tr></table><p><a name="IXT-5-123089" /><a name="IXT-5-123090" /><a name="IXT-5-123091" /><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch05_07.htm"><img src="../gifs/txtpreva.gif" alt="Previous" border="0" /></a></td><td align="center" valign="top" width="228"><a href="index.htm"><img src="../gifs/txthome.gif" alt="Home" border="0" /></a></td><td align="right" valign="top" width="228"><a href="part2.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td align="left" valign="top" width="228">5.7. Invoking the Shell</td><td align="center" valign="top" width="228"><a href="index/index.htm"><img src="../gifs/index.gif" alt="Book Index" border="0" /></a></td><td align="right" valign="top" width="228">II. Text Editing and Processing</td></tr></table></div><hr width="684" align="left" /><img src="../gifs/navbar.gif" usemap="#library-map" border="0" alt="Library Navigation Links" /><p><p><font size="-1"><a href="copyrght.htm">Copyright &copy; 2003</a> O'Reilly &amp; Associates. All rights reserved.</font></p><map name="library-map"><area shape="rect" coords="1,0,88,96" href="../index.htm"><area shape="rect" coords="90,0,165,96" href="../upt/index.htm"><area shape="rect" coords="168,1,253,107" href="../mac/index.htm"><area shape="rect" coords="255,0,335,97" href="../korn/index.htm"><area shape="rect" coords="337,0,415,109" href="../unixnut/index.htm"><area shape="rect" coords="417,0,512,122" href="../sedawk/index.htm"><area shape="rect" coords="514,0,605,105" href="../lunix/index.htm"><area shape="rect" coords="611,2,694,121" href="../vi/index.htm"></map></body></html>

⌨️ 快捷键说明

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