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

📄 ch04_03.htm

📁 unix基础教程
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<tr><td><p><tt class="literal">LC_NUMERIC=</tt><em class="replaceable"><tt>locale</tt></em></p></td><td><p>(K93) Locale to use for the decimal-point character.<a name="IXT-4-122739" /></p></td></tr><tr><td><p><tt class="literal">LINES=</tt><em class="replaceable"><tt>n</tt></em></p></td><td><p>(K) Screen's height; used for <tt class="literal">select</tt> lists.<a name="IXT-4-122740" /></p></td></tr><tr><td><p><tt class="literal">MAIL=</tt><em class="replaceable"><tt>file</tt></em></p></td><td><p>Default file in which to receive mail; set by <tt class="literal">login</tt>.<a name="IXT-4-122741" /></p></td></tr><tr><td><p><tt class="literal">MAILCHECK=</tt><em class="replaceable"><tt>n</tt></em></p></td><td><p>Number of seconds between mail checks; default is 600 (10 minutes).<a name="IXT-4-122742" /></p></td></tr><tr><td><p><tt class="literal">MAILPATH=</tt><em class="replaceable"><tt>files</tt></em></p></td><td><p><a name="IXT-4-122743" />One or more files, delimited by a colon, in which to receive mail.Along with each file, you may supply an optional message that the shellprints when the file increases in size. Messages are separatedfrom the file name by a separator character.The Korn shell separator is <tt class="literal">?</tt>, and the default messageis <tt class="literal">You have mail in $_</tt>.<tt class="literal">$_</tt> is replaced with the name of the file.The Bourne shell separator is <tt class="literal">%</tt>, andthe default message is <tt class="literal">You have mail</tt>.For example, for <tt class="literal">ksh</tt>, you might have:<blockquote><pre class="code">MAILPATH="$MAIL?Ring! Candygram!:/etc/motd?New Login Message"</pre></blockquote></p></td></tr><tr><td><p><tt class="literal">PATH=</tt><em class="replaceable"><tt>dirlist</tt></em></p></td><td><p>One or more pathnames, delimited by colons, in which to search<a name="IXT-4-122744" />for commands to execute.Default for SVR4 is <tt class="literal">/bin:/usr/bin</tt>.On Solaris, the default is<tt class="literal">/usr/bin:</tt>.However, the standard start-up scripts change it to:<blockquote><pre class="code">/usr/bin:/usr/ucb:/etc:.</pre></blockquote><tt class="literal">ksh93</tt>: PATH is also searched forfunction definitionsfor undefined functions.</p></td></tr><tr><td><p><tt class="literal">PS1=</tt><em class="replaceable"><tt>string</tt></em></p></td><td><p>Primary prompt string; default is <tt class="literal">$</tt>.<a name="IXT-4-122745" /></p></td></tr><tr><td><p><tt class="literal">PS2=</tt><em class="replaceable"><tt>string</tt></em></p></td><td><p>Secondary prompt (used in multiline commands); default is <tt class="literal">&gt;</tt>.</p></td></tr><tr><td><p><tt class="literal">PS3=</tt><em class="replaceable"><tt>string</tt></em></p></td><td><p>(K) Prompt string in <tt class="literal">select</tt> loops; default is <tt class="literal">#?</tt>.</p></td></tr><tr><td><p><tt class="literal">PS4=</tt><em class="replaceable"><tt>string</tt></em></p></td><td><p>(K) Prompt string for execution trace (<tt class="literal">ksh -x</tt> or <tt class="literal">set -x</tt>);default is <tt class="literal">+</tt>.</p></td></tr><tr><td><p><tt class="literal">SHACCT=</tt><em class="replaceable"><tt>file</tt></em></p></td><td><p>&#8220;Shell account&#8221;; file in which to log executed shell scripts.<a name="IXT-4-122746" />Not in Korn shell.</p></td></tr><tr><td><p><tt class="literal">SHELL=</tt><em class="replaceable"><tt>file</tt></em></p></td><td><p>Name of default shell (e.g., <tt class="literal">/bin/sh</tt>).<a name="IXT-4-122747" /></p></td></tr><tr><td><p><tt class="literal">TERM=</tt><em class="replaceable"><tt>string</tt></em></p></td><td><p>Terminal type.<a name="IXT-4-122748" /></p></td></tr><tr><td><p><tt class="literal">TMOUT=</tt><em class="replaceable"><tt>n</tt></em></p></td><td><p><a name="IXT-4-122749" />(K) If no command is typed after <em class="emphasis">n</em> seconds, exit the shell.</p></td></tr><tr><td><p><tt class="literal">VISUAL=</tt><em class="replaceable"><tt>path</tt></em></p></td><td><p><a name="IXT-4-122750" />(K) Same as EDITOR, but VISUAL is checked first.</p></td></tr></table><p><a name="IXT-4-122751" /></div><a name="unut-ch-4-sect-3.4" /><div class="sect2"><h3 class="sect2">4.3.4. Arrays</h3><p><a name="IXT-4-122752" /><a name="IXT-4-122753" />The Korn shell supports one-dimensional arrays of up to 1024 elements.The first element is numbered 0.An array <em class="emphasis">name</em> can be initialized as follows:</p><blockquote><pre class="code">set -A <em class="replaceable"><tt>name value0 value1 ...</tt></em></pre></blockquote><p>where the specified values become elements of <em class="emphasis">name</em>.Declaring arrays is not required, however.  Any valid reference toa subscripted variable can create an array.</p><p><a name="IXT-4-122754" />When referencing arrays, use the<tt class="literal">${</tt> ... <tt class="literal">}</tt> syntax.This isn't needed when referencing arraysinside <tt class="literal">(( ))</tt> (the form of <tt class="literal">let</tt> that does automatic quoting).Note that <tt class="literal">[</tt> and <tt class="literal">]</tt> are typed literally(i.e., they don't stand for optional syntax).</p><table border="1" cellpadding="3"><tr><td><p><tt class="literal">${</tt><em class="replaceable"><tt>name</em><tt class="literal">[</tt><em class="replaceable">i</tt></em><tt class="literal">]}</tt></p></td><td><p>Use element <em class="emphasis">i</em> of array <em class="emphasis">name</em>.<em class="emphasis">i</em> can be any arithmetic expressionas described under <tt class="literal">let</tt>.The expression must return a value between 0 and 1023.</p></td></tr><tr><td><p><tt class="literal">${</tt><em class="replaceable"><tt>name</tt></em><tt class="literal">}</tt></p></td><td><p>Use element 0 of array <em class="emphasis">name</em>.</p></td></tr><tr><td><p><tt class="literal">${</tt><em class="replaceable"><tt>name</tt></em><tt class="literal">[*]}</tt></p><p><tt class="literal">${</tt><em class="replaceable"><tt>name</tt></em><tt class="literal">[@]}</tt></p></td><td><p>Use all elements of array <em class="emphasis">name</em>.</p></td></tr><tr><td><p><tt class="literal">${#</tt><em class="replaceable"><tt>name</tt></em><tt class="literal">[*]}</tt></p><p><tt class="literal">${#</tt><em class="replaceable"><tt>name</tt></em><tt class="literal">[@]}</tt></p></td><td><p>Use the number of elements in array <em class="emphasis">name</em>.</p></td></tr></table><p><p><tt class="literal">ksh93</tt> provides associative arrays, where the indicesare strings instead of numbers (as in <tt class="literal">awk</tt>).In this case,<tt class="literal">[</tt> and <tt class="literal">]</tt> act like double quotes.Associative arrays are created with <tt class="literal">typeset -A</tt>.A special syntax allows assigning to multiple elements at once:</p><blockquote><pre class="code">data=([joe]=30 [mary]=25)</pre></blockquote><p>The values would be retrieved as <tt class="literal">${data[joe]}</tt>and <tt class="literal">${data[mary]}</tt>.</p><a name="IXT-4-122755" /><a name="IXT-4-122756" /><a name="IXT-4-122757" /></div><a name="unut-ch-4-sect-3.5" /><div class="sect2"><h3 class="sect2">4.3.5. Discipline Functions (ksh93 only)</h3><p><a name="IXT-4-122758" /><a name="IXT-4-122759" />Along with structured variables,<tt class="literal">ksh93</tt> introduces <em class="emphasis">discipline functions</em>.These are special functions that are called whenever a variable'svalue is accessed or changed.For a shell variable named <tt class="literal">x</tt>, you candefine the following functions:</p><table border="1" cellpadding="3"><tr><td><tt class="literal">x.get</tt></td><td><p>Called when <tt class="literal">x</tt>'s valueis retrieved (<tt class="literal">$x</tt>).</p></td></tr><tr><td><tt class="literal">x.set</tt></td><td><p>Called when <tt class="literal">x</tt>'s valueis changed (<tt class="literal">x=2</tt>).</p></td></tr><tr><td><tt class="literal">x.unset</tt></td><td><p>Called when <tt class="literal">x</tt> isunset (<tt class="literal">unset x</tt>).</p></td></tr></table><p><p>Within the discipline functions, special variables provide informationabout the variable being changed:</p><table border="1" cellpadding="3"><tr><td><tt class="literal">.sh.name</tt></td><td><p>The name of the variable being changed.</p></td></tr><tr><td><tt class="literal">.sh.subscript</tt></td><td><p>The subscript of the array element being changed.</p></td></tr><tr><td><tt class="literal">.sh.value</tt></td><td><p>The value of the variable being assigned orreturned.  Changing it within the discipline functionchanges the value that is actually assigned or returned.</p></td></tr></table><p></div><hr width="684" align="left" /><div class="navbar"><table width="684" border="0"><tr><td align="left" valign="top" width="228"><a href="ch04_02.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="ch04_04.htm"><img src="../gifs/txtnexta.gif" alt="Next" border="0" /></a></td></tr><tr><td align="left" valign="top" width="228">4.2. Syntax</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">4.4. Arithmetic Expressions</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 + -