ch04_09.htm
来自「unix基础教程」· HTM 代码 · 共 1,119 行 · 第 1/5 页
HTM
1,119 行
<dt><tt class="literal">%P</tt></dt><dd>Translate <tt class="literal">egrep</tt> extended regular expressioninto <tt class="literal">ksh</tt> pattern.</p></dd><dt><tt class="literal">%q</tt></dt><dd>Print a quoted string that canbe reread later on.</p></dd></dl></td></tr><tr><td valign="top"><a name="pwd">pwd</a></a></td><td><p><tt class="literal">pwd</tt></p><p><tt class="literal">pwd</tt> [<tt class="literal">-LP</tt>]</p><p><a name="IXT-4-122869" />Print your present working directory on standard output.The second form is specific to the Korn shell.</p><h4 class="refsect2">Options</h4><p>Options give control over the use of logical versus physicaltreatment of the printed path.See the entry for <b class="emphasis-bold"><a href="#cd">cd</a></b>, earlier in this section.</p><dl><dt><tt class="literal">-L</tt></dt><dd>Use logical path (what the user typed, including any symbolic links)and the value of PWD for the current directory.This is the default.</p></dd><dt><tt class="literal">-P</tt></dt><dd>Use the actual filesystem physical pathfor the current directory.</p></dd></dl></td></tr><tr><td valign="top"><a name="r">r</a></a></td><td><tt class="literal">r</tt><p><a name="IXT-4-122870" />Reexecute previous command.<tt class="literal">ksh88</tt> alias for <tt class="literal">fc -e -</tt>.<tt class="literal">ksh93</tt> alias for <tt class="literal">hist -s</tt>.</p></td></tr><tr><td valign="top"><a name="read">read</a></a></td><td><tt class="literal">read</tt> <em class="replaceable"><tt>variable1</em> [<em class="replaceable">variable2 ...</tt></em>]<p><a name="IXT-4-122871" />Read one line of standard input and assign each word tothe corresponding<em class="emphasis">variable</em>, with all leftover words assigned to the last variable. Ifonly one variable is specified, the entire line will be assigned tothat variable. See the Examples here and under <tt class="literal">case</tt>.The return status is 0 unless <em class="emphasis">EOF</em> is reached.</p><h4 class="refsect2">Example</h4><blockquote><pre class="code">$ <tt class="userinput"><b>read first last address</b></tt>Sarah Caldwell 123 Main Street$ <tt class="userinput"><b>echo "$last, $first\n$address"</b></tt><tt class="userinput"><b>Caldwell, Sarah123 Main Street</b></tt></pre></blockquote></td></tr><tr><td valign="top"><a name="read">read</a></a></td><td><tt class="literal">read</tt> [<em class="replaceable"><tt>options</em>] [<em class="replaceable">variable1</em>[<tt class="literal">?</tt><em class="replaceable">string</em>]] [<em class="replaceable">variable2</tt></em> ...]<p><a name="IXT-4-122872" />Korn shell only. Same as in the Bourne shell, except that the Korn shell versionsupports the following options as well as the <tt class="literal">?</tt> syntax for prompting.If the first variable is followed by <tt class="literal">?</tt><em class="emphasis">string</em>,<em class="emphasis">string</em> is displayedas a user prompt. If no variables are given, input is stored in theREPLY variable.Additionally, <tt class="literal">ksh93</tt> allows you to specify atimeout.</p><h4 class="refsect2">Options</h4><dl><dt><tt class="literal">-A</tt> <tt><em class="replaceable">array</em></tt></dt><dd>Read into indexed array <em class="emphasis">array</em></tt>.<tt class="literal">ksh93</tt> only.</p></dd><dt><tt class="literal">-d</tt> <tt><em class="replaceable">delim</em></tt></dt><dd>Read up to first occurrence of <em class="emphasis">delim</em></tt>,instead of newline.<tt class="literal">ksh93</tt> only.</p></dd><dt><tt class="literal">-p</tt></dt><dd>Read from the output of a <tt class="literal">|&</tt> coprocess.</p></dd><dt><tt class="literal">-r</tt></dt><dd>Raw mode; ignore \ as a line continuation character.</p></dd><dt><tt class="literal">-s</tt></dt><dd>Save input as a command in the history file.</p></dd><dt><tt class="literal">-t</tt> <tt><em class="replaceable">timeout</em></tt></dt><dd>When reading from a terminal or pipe,if no data is entered after <em class="emphasis">timeout</em> seconds,return <tt class="literal">l</tt>.This prevents an application from hanging forever, waiting foruser input.<tt class="literal">ksh93</tt> only.</p></dd><dt><tt class="literal">-u</tt>[<tt><em class="replaceable">n</em></tt>]</dt><dd>Read input from file descriptor <em class="emphasis">n</em></tt> (default is 0).</p></dd></dl><h4 class="refsect2">Example</h4><p>Prompt yourself to enter two temperatures:</p><blockquote><pre class="code">$ <tt class="userinput"><b>read n1?"High low: " n2</b></tt>High low: <tt class="userinput"><b>65 33</b></tt></pre></blockquote></td></tr><tr><td valign="top"><a name="readonly">readonly</a></a></td><td><tt class="literal">readonly</tt> [<tt><em class="replaceable"><tt>variable1 variable2</tt></em></tt> ...]<br><tt class="literal">readonly -p</tt><p><a name="IXT-4-122873" />Prevent the specified shell variables from being assigned new values.Variables can be accessed (read) but not overwritten.In the Korn shell, the syntax <em class="emphasis">variable</em></tt><tt class="literal">=</tt><em class="emphasis">value</em></tt> canassign a new value that cannot be changed.The second form is specific to <tt class="literal">ksh93</tt>.</p><h4 class="refsect2">Option</h4><dl><dt><tt class="literal">-p</tt></dt><dd>Print <tt class="literal">readonly</tt> before printing thenames and values of read-only variables.This allows saving a list of read-only variables for rereading later.</p></dd></dl></td></tr><tr><td valign="top"><a name="redirect">redirect</a></a></td><td><tt class="literal">redirect</tt> <em class="replaceable"><tt>i/o-redirection</tt></em> ... <p><tt class="literal">ksh93</tt> alias for <tt class="literal">command exec</tt>.<a name="IXT-4-122874" /></p><h4 class="refsect2">Example</h4><p>Change the shell's standard error to the console:</p><blockquote><pre class="code">$ <tt class="userinput"><b>redirect 2>/dev/console</b></tt></pre></blockquote></td></tr><tr><td valign="top"><a name="return">return</a></a></td><td><tt class="literal">return</tt> [<em class="replaceable"><tt>n</tt></em>]<p><a name="IXT-4-122875" />Use inside a function definition.Exit the function with status <em class="emphasis">n</em> or with the exit status of the previously executed command.</p></td></tr><tr><td valign="top"><a name="select">select</a></a></td><td><tt class="literal">select</tt> <em class="replaceable"><tt>x</em> [<tt class="literal">in</tt> <em class="replaceable">list</em>]<br><tt class="literal">do</tt><br>    <em class="replaceable">commands</tt></em><br><tt class="literal">done</tt><p><a name="IXT-4-122876" />Korn shell only.Display a list of menu items on standard error, numbered in theorder they are specified in <em class="emphasis">list</em>.If no <tt class="literal">in</tt> <em class="emphasis">list</em> is given,items are taken from the command line (via<tt class="literal">"$@"</tt>).Following the menu is a prompt string (set by PS3).At the PS3 prompt, users select a menu item by typing itsline number, or they redisplay the menu by pressing the Return key. (User input isstored in the shell variable REPLY.)If a valid line number is typed, <em class="emphasis">commands</em> are executed.Typing <em class="emphasis">EOF</em> terminates the loop.</p><h4 class="refsect2">Example</h4><blockquote><pre class="code">PS3="Select the item number: "select event in Format Page View Exitdo case "$event" in Format) nroff $file | lp;; Page) pr $file | lp;; View) more $file;; Exit) exit 0;; * ) echo "Invalid selection";; esacdone</pre></blockquote><p>The output of this script looks like this:</p><blockquote><pre class="code">1. Format2. Page3. View4. ExitSelect the item number:</pre></blockquote></td></tr><tr><td valign="top"><a name="set">set</a></a></td><td><tt class="literal">set</tt> [<em class="replaceable"><tt>options arg1 arg2 ...</tt></em>]<p><a name="IXT-4-122877" />With no arguments, <tt class="literal">set</tt> prints the values of all variablesknown to the current shell. Options can be enabled(<tt class="literal">-</tt><em class="emphasis">option</em>) or disabled (+<em class="emphasis">option</em>).Options can also be set when the shell is invoked,via <tt class="literal">ksh</tt> or <tt class="literal">sh</tt>.(See the earlier <a href="ch04_07.htm#unut-ch-4-sect-7">Section 4.7</a>.) Arguments are assigned in order to <tt class="literal">$1</tt>,<tt class="literal">$2</tt>, etc.</p><h4 class="refsect2">Options</h4><dl><dt><tt class="literal">+A</tt> <tt><em class="replaceable">name</em></tt></dt><dd>Assign remaining arguments as elements of array <em class="emphasis">name</em></tt>. Kornshell only.</p></dd><dt><tt class="literal">-A</tt> <tt><em class="replaceable">name</em></tt></dt><dd>Same as <tt class="literal">+A</tt>, but unset <em class="emphasis">name</em></tt> before making assignments.Korn shell only.</p></dd><dt><tt class="literal">-a</tt></dt><dd>From now on automatically mark variables for exportafter defining or changing them.</p></dd><dt><tt class="literal">-b</tt></dt><dd>Same as <tt class="literal">-o notify</tt>.The single-letter form is only in <tt class="literal">ksh93</tt>.</p></dd><dt><tt class="literal">-C</tt></dt><dd>Same as <tt class="literal">-o noclobber</tt>.The single-letter form is only in <tt class="literal">ksh93</tt>.</p></dd><dt><tt class="literal">-e</tt></dt><dd>Exit if a command yields a nonzero exit status.In the Korn shell, the <tt class="literal">ERR</tt> trap is executedbefore the shell exits.</p></dd><dt><tt class="literal">-f</tt></dt><dd>Ignore filename metacharacters (e.g., <tt class="literal">* ? [ ]</tt>).</p></dd><dt><tt class="literal">-h</tt></dt><dd>Locate commands as they are defined. The Korn shell createstracked aliases, whereas the Bourne shell hashes command names.See <b class="emphasis-bold"><a href="#hash">hash</a></b>.</p></dd><dt><tt class="literal">-k</tt></dt><dd>Assignment of environment variables (<em class="emphasis">var</em></tt><tt class="literal">=</tt><em class="emphasis">value</em></tt>) takes effect regardless of where they appear on thecommand line. Normally, assignments must precede the command name.</p></dd><dt><tt class="literal">-m</tt></dt><dd>Enable job control; background jobs execute in a separate processgroup. <tt class="literal">-m</tt> is usually set automatically. Kornshell only.</p></dd><dt><tt class="literal">-n</tt></dt><dd>Read commands but don't execute; useful for checking syntax.The Korn shell ignores this option if it is interactive.</p></dd><dt><tt class="literal">-o</tt> [<tt><em class="replaceable">mode</em></tt>]</dt><dd>List Korn shell modes, or turn on mode <em class="emphasis">mode</em></tt>.Many modes can be set by other options. Modes are:</p></dd></dl><table border="1" cellpadding="3"><tr><td><tt class="literal">allexport</tt></td><td><p>Same as <tt class="literal">-a</tt>.</p></td></tr><tr><td><tt class="literal">bgnice</tt></td><td><p>Run background jobs at lower priority.</p></td></tr><tr><td><tt class="literal">emacs</tt></td><td><p>Set command-line editor to <tt class="literal">emacs</tt>.</p></td></tr><tr><td><tt class="literal">errexit</tt></td><td><p>Same as <tt class="literal">-e</tt>.</p></td></tr><tr><td><tt class="literal">ignoreeof</tt></td><td><p>Don't process <em class="emphasis">EOF</em> signals.To exit the shell, type <tt class="literal">exit</tt>.</p></td></tr><tr><td><tt class="literal">keyword</tt></td><td><p>Same as <tt class="literal">-k</tt>.</p></td></tr><tr><td><tt class="literal">markdirs</tt></td><td><p>Append / to directory names.</p></td></tr><tr><td><tt class="literal">monitor</tt></td><td><p>Same as <tt class="literal">-m</tt>.</p></td></tr><tr><td><tt class="literal">noclobber</tt></td><td><p>Prevent overwriting via <tt class="literal">></tt> redirection;use <tt class="literal">>|</tt> to overwrite files.</p></td></tr><tr><td><tt class="literal">noexec</tt></td><td><p>Same as <tt class="literal">-n</tt>.</p></td></tr><tr><td><tt class="literal">noglob</tt></td><td><p>Same as <tt class="literal">-f</tt>.</p></td></tr><tr><td><tt class="literal">nolog</tt></td><td><p>Omit function definitions from history file.</p></td></tr><tr><td><tt class="literal">notify</tt></td><
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?