ch04_09.htm

来自「unix基础教程」· HTM 代码 · 共 1,119 行 · 第 1/5 页

HTM
1,119
字号
</td></tr><tr><td valign="top"><a name="hash">hash</a></a></td><td><tt class="literal">hash</tt><p><a name="IXT-4-122856" />Korn shell alias for <tt class="literal">alias -t</tt>(<tt class="literal">alias -t --</tt> in <tt class="literal">ksh93</tt>).Emulates Bourne shell's <tt class="literal">hash</tt>.</p></td></tr><tr><td valign="top"><a name="hist">hist</a></a></td><td><tt class="literal">hist</tt> [<em class="replaceable"><tt>options</em>] [<em class="replaceable">first</em> [<em class="replaceable">last</em>]]<br><tt class="literal">hist -s</tt> [<em class="replaceable">old</em><tt class="literal">=</tt><em class="replaceable">new</em>] [<em class="replaceable">command</tt></em>]<p><a name="IXT-4-122857" /><tt class="literal">ksh93</tt> only.  Display or edit commands in the history list.(Use only one of <tt class="literal">-l</tt> or <tt class="literal">-s</tt>.)<em class="emphasis">first</em> and <em class="emphasis">last</em> are numbers orstrings specifying the range of commands to display or edit.If <em class="emphasis">last</em> is omitted, <tt class="literal">hist</tt>applies to a single command (specifiedby <em class="emphasis">first</em>).If both <em class="emphasis">first</em> and <em class="emphasis">last</em> are omitted,<tt class="literal">hist</tt> edits the previous command or lists the last 16.The second form of <tt class="literal">hist</tt> takesa history <em class="emphasis">command</em>,replaces <em class="emphasis">old</em> string with <em class="emphasis">new</em> string,and executes the modified command.  If no strings arespecified, <em class="emphasis">command</em> is just reexecuted.If no <em class="emphasis">command</em>is given either, the previous command is reexecuted.<em class="emphasis">command</em> is a number or string like <em class="emphasis">first</em>.See the examples in <a href="ch04_05.htm#unut-ch-4-sect-5">Section 4.5</a>.</p><h4 class="refsect2">Options</h4><dl><dt><tt class="literal">-e</tt> [<tt><em class="replaceable">editor</em></tt>]</dt><dd>Invoke <em class="emphasis">editor</em></tt> to edit the specified history commands.The default <em class="emphasis">editor</em></tt> is set by the shell variable HISTEDIT.If that variable is not set, FCEDIT is used.If neither is set, the default is <tt class="literal">/bin/ed</tt>.</p></dd><dt><tt class="literal">-l</tt></dt><dd>List the specified command or range of commands, or list the last 16.</p></dd><dt><tt class="literal">-n</tt></dt><dd>Suppress command numbering from the <tt class="literal">-l</tt> listing.</p></dd><dt><tt class="literal">-r</tt></dt><dd>Reverse the order of the <tt class="literal">-l</tt> listing.</p></dd><dt><tt class="literal">-s</tt></dt><dd>Execute (or redo) a history command; referto second syntax line above.</p></dd></dl></td></tr><tr><td valign="top"><a name="history">history</a></a></td><td><p><tt class="literal">history</tt></p><p><a name="IXT-4-122858" />Show the last 16 commands.<tt class="literal">ksh88</tt> alias for <tt class="literal">fc -l</tt>.<tt class="literal">ksh93</tt> alias for <tt class="literal">hist -l</tt>.</p></td></tr><tr><td valign="top"><a name="if">if</a></a></td><td><tt class="literal">if</tt> <tt><em class="replaceable"><tt>condition1</em></tt><br><tt class="literal">then</tt> <tt><em class="replaceable">commands1</em></tt> <br>[ <tt class="literal">elif</tt> <tt><em class="replaceable">condition2</em></tt><br>&#160;&#160;&#160;&#160;<tt class="literal">then</tt> <tt><em class="replaceable">commands2</em></tt> ]<br> .<br> .<br> .<br>[ <tt class="literal">else</tt> <tt><em class="replaceable">commands3</tt></em></tt> ]<br><tt class="literal">fi</tt><p><a name="IXT-4-122859" />If <em class="emphasis">condition1</em></tt> is met, do <em class="emphasis">commands1</em></tt>; otherwise, if<em class="emphasis">condition2</em></tt> is met, do <em class="emphasis">commands2</em></tt>; if neither is met, do<em class="emphasis">commands3</em></tt>.Conditions are usually specified with the <tt class="literal">test</tt>and <tt class="literal">[[ ]]</tt>commands.See <b class="emphasis-bold"><a href="#test">test</a></b> and <b class="emphasis-bold">[[ ]]</b>for a full list of conditions, andsee additional Examples under <b class="emphasis-bold"><a href="#:">:</a></b>and <b class="emphasis-bold"><a href="#exit">exit</a></b>.</p><h4 class="refsect2">Examples</h4><p>Insert a 0 before numbers less than 10: </p><blockquote><pre class="code">if [ $counter -lt 10 ]then number=0$counterelse number=$counterfi</pre></blockquote><p>Make a directory if it doesn't exist:</p><blockquote><pre class="code">if [ ! -d $dir ]; then   mkdir $dir   chmod 775 $dirfi</pre></blockquote></td></tr><tr><td valign="top"><a name="integer">integer</a></a></td><td><tt class="literal">integer</tt><p><a name="IXT-4-122860" />Specify integer variables.Korn shell alias for <tt class="literal">typeset -i</tt>.</p></td></tr><tr><td valign="top"><a name="jobs">jobs</a></a></td><td><tt class="literal">jobs</tt> [<tt><em class="replaceable"><tt>options</em></tt>] [<tt><em class="replaceable">jobIDs</tt></em></tt>]<p><a name="IXT-4-122861" />List all running or stopped jobs, or list those specified by <em class="emphasis">jobIDs</em></tt>.  For example, you can check whether a long compilation or text formatis still running.  Also useful before logging out. See <a href="ch04_06.htm#unut-ch-4-sect-6">Section 4.6</a></p><h4 class="refsect2">Options</h4><dl><dt><tt class="literal">-l</tt></dt><dd>List job IDs and process group IDs.</p></dd><dt><tt class="literal">-n</tt></dt><dd>List only jobs whose status changed since last notification.  Kornshell only.</p></dd><dt><tt class="literal">-p</tt></dt><dd>List process group IDs only.</p></dd><dt><tt class="literal">-x</tt> <tt><em class="replaceable">cmd</em></tt></dt><dd>Replace each job ID found in <em class="emphasis">cmd</em></tt> with the associated process IDand then execute <em class="emphasis">cmd</em></tt>.  Not valid for Korn shell.</p></dd></dl></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">IDs</tt></em></tt><p><a name="IXT-4-122862" />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>. See <a href="ch04_06.htm#unut-ch-4-sect-6">Section 4.6</a>.</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">-n</tt> <tt><em class="replaceable">num</em></tt></dt><dd>Send the given signal number. <tt class="literal">ksh93</tt> only.</p></dd><dt><tt class="literal">-s</tt> <tt><em class="replaceable">name</em></tt></dt><dd>Send the given signal name. <tt class="literal">ksh93</tt> only.</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 the ones 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></td></tr><tr><td valign="top"><a name="let">let</a></a></td><td><tt class="literal">let</tt> <tt><em class="replaceable"><tt>expressions</em></tt><br>&#160;&#160;&#160;&#160;&#160;or <br><tt class="literal">((</tt><tt><em class="replaceable">expressions</tt></em></tt><tt class="literal">))</tt><p><a name="IXT-4-122863" />Korn shell only.  Perform arithmetic as specified by one or more <em class="emphasis">expressions</em></tt>.<em class="emphasis">expressions</em></tt> consist of numbers, operators, andshell variables (which don't need a preceding <tt class="literal">$</tt>).Expressions must be quoted if they contain spaces or other special characters.The <tt class="literal">(( ))</tt> form does the quoting for you.  For more information and examples, see &#8220;Arithmetic Expressions&#8221; earlier in this chapter.See also <b class="emphasis-bold"><a href="#expr">expr</a></b> in <a href="ch02_01.htm">Chapter 2</a>.</p><h4 class="refsect2">Examples</h4><p>Each of these examples adds 1 to variable <tt class="literal">i</tt>:</p><blockquote><pre class="code">i=`expr $i + 1`	<i class="lineannotation">sh, ksh88, ksh93</i>let i=i+1		<i class="lineannotation">ksh88 and ksh93</i>let "i = i + 1"(( i = i + 1 ))(( i += 1 ))(( i++ ))		<i class="lineannotation">ksh93 only</i></pre></blockquote></td></tr><tr><td valign="top"><a name="nameref">nameref</a></a></td><td><tt class="literal">nameref</tt> <tt><em class="replaceable"><tt>newvar</em></tt><tt class="literal">=</tt><tt><em class="replaceable">oldvar</tt></em></tt> ...<p><a name="IXT-4-122864" /><tt class="literal">ksh93</tt> alias for <tt class="literal">typeset -n</tt>.See the discussion of indirect variables in <a href="ch04_03.htm#unut-ch-4-sect-3">Section 4.3</a> earlier in this chapter.</p></td></tr><tr><td valign="top"><a name="newgrp">newgrp</a></a></td><td><tt class="literal">newgrp</tt> [<tt><em class="replaceable"><tt>group</tt></em></tt>]<p><a name="IXT-4-122865" />Change your group ID to <em class="emphasis">group</em></tt>, or return to your default group.On modern Unix systems where users can be in multiple groups,this command is obsolete.</p></td></tr><tr><td valign="top"><a name="nohup">nohup</a></a></td><td><tt class="literal">nohup</tt><p><a name="IXT-4-122866" />Don't terminatea command after log out.<tt class="literal">nohup</tt> is a Korn shell alias:</p><blockquote><pre class="code">nohup='nohup '</pre></blockquote><p>The embedded space at the end lets <tt class="literal">nohup</tt>interpret the following command as an alias, if needed.</p></td></tr><tr><td valign="top"><a name="print">print</a></a></td><td><tt class="literal">print</tt> [<tt><em class="replaceable"><tt>options</em></tt>] [<tt><em class="replaceable">string</tt></em></tt> ...]<p><a name="IXT-4-122867" />Korn shell only.Display <em class="emphasis">string</em></tt> (on standard output by default).<tt class="literal">print</tt> includes thefunctions of <tt class="literal">echo</tt> and can be used in its place on most Unix systems.</p><h4 class="refsect2">Options</h4><dl><dt><tt class="literal">-</tt></dt><dd>Ignore all subsequent options.</p></dd><dt><tt class="literal">--</tt></dt><dd>Same as <tt class="literal">&#8211;</tt>.</p></dd><dt><tt class="literal">-f</tt> <tt><em class="replaceable">format</em></tt></dt><dd>Print like <tt class="literal">printf</tt>,using <em class="emphasis">format</em> as the format string.Ignores the <tt class="literal">-n</tt>, <tt class="literal">-r</tt>,and <tt class="literal">-R</tt> options.<tt class="literal">ksh93</tt> only.</p></dd><dt><tt class="literal">-n</tt></dt><dd>Don't end output with a newline.</p></dd><dt><tt class="literal">-p</tt></dt><dd>Send <em class="emphasis">string</em></tt> to the process created by <tt class="literal">|&amp;</tt>,instead of to standard output.</p></dd><dt><tt class="literal">-r</tt></dt><dd>Ignore the escape sequences often used with <tt class="literal">echo</tt>.</p></dd><dt><tt class="literal">-R</tt></dt><dd>Same as <tt class="literal">-r</tt> and ignore subsequent options(except <tt class="literal">-n</tt>).</p></dd><dt><tt class="literal">-s</tt></dt><dd>Send <em class="emphasis">string</em></tt> to the history file.</p></dd><dt><tt class="literal">-u</tt>[<tt><em class="replaceable">n</em></tt>]</dt><dd>Send <em class="emphasis">string</em></tt> to file descriptor <em class="emphasis">n</em></tt> (default is 1).</p></dd></dl></td></tr><tr><td valign="top"><a name="printf">printf</a></a></td><td><tt class="literal">printf</tt> <em class="replaceable"><tt>format</em> [<em class="replaceable">val</tt></em> ...]<p><a name="IXT-4-122868" /> <tt class="literal">ksh93</tt> only.Formatted printing, like the ANSI C <tt class="literal">printf</tt>function.</p><h4 class="refsect2">Additional Format Letters</h4><dl><dt><tt class="literal">%b</tt></dt><dd>Expand escape sequences in strings (e.g., <tt class="literal">\t</tt>to tab, and so on).</p></dd><dt><tt class="literal">%d</tt></dt><dd>An additional period and the output base can follow the precision(e.g., <tt class="literal">%5.3.6d</tt> to produce outputin base 6).</p></dd>

⌨️ 快捷键说明

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