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

📄 read.html

📁 unix 下的C开发手册,还用详细的例程。
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>read</title></head><body bgcolor=white><center><font size=2>The Single UNIX &reg; Specification, Version 2<br>Copyright &copy; 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_001_014_1840">&nbsp;</a>NAME</h4><blockquote>read - read a line from standard input</blockquote><h4><a name = "tag_001_014_1841">&nbsp;</a>SYNOPSIS</h4><blockquote><pre><code>read <b>[</b>-r<b>]</b><i> var</i>...</code></pre></blockquote><h4><a name = "tag_001_014_1842">&nbsp;</a>DESCRIPTION</h4><blockquote>The<i>read</i>utility will read a single line from standard input.<p>By default, unless the<b>-r</b>option is specified, backslash(\)acts as an escape character, as described in<xref href=esc><a href="chap2.html#tag_001_002_001">Escape Character (Backslash)</a></xref>.If standard input is a terminal device and the invoking shellis interactive,<i>read</i>will prompt for a continuation line when:<ul><p><li>The shell reads an input lineending with a backslash, unless the<b>-r</b>option is specified.<p><li>A here-document is not terminated after anewline characteris entered.<p></ul><p>The line will be split into fieldsas in the shell (see<xref href=fldspl><a href="chap2.html#tag_001_006_005">Field Splitting</a></xref>);the first field will be assigned to the firstvariable<i>var,</i>the second field to the second variable<i>var,</i>and so on.If there are fewer<i>var</i>operands specified than there are fields, the leftoverfields and their intervening separators will be assigned to the last<i>var</i>.If there are fewer fields than<i>var</i>s,the remaining<i>var</i>swill be set to empty strings.<p>The setting of variables specified by the<i>var</i>operands will affect the current shell execution environment; see<xref href=shexenv><a href="chap2.html#tag_001_012">Shell Execution Environment</a></xref>.If it is called in a subshell or separate utility execution environment,such as one of the following:<pre><code>(read foo)nohup read ...find . -exec read ... \;</code></pre>it will not affect the shell variables in the caller's environment.</blockquote><h4><a name = "tag_001_014_1843">&nbsp;</a>OPTIONS</h4><blockquote>The<i>read</i>utility supports the <b>XBD</b> specification, <a href="../xbd/utilconv.html#usg"><b>Utility Syntax Guidelines</b>&nbsp;</a> .<p>The following option is supported:<dl compact><dt><b>-r</b><dd>Do not treat a backslash character in any special way.Consider each backslash to be part of the input line.</dl></blockquote><h4><a name = "tag_001_014_1844">&nbsp;</a>OPERANDS</h4><blockquote>The following operands are supported:<dl compact><dt><i>var</i><dd>The name of an existing or non-existing shell variable.</dl></blockquote><h4><a name = "tag_001_014_1845">&nbsp;</a>STDIN</h4><blockquote>The standard input must be a text file.</blockquote><h4><a name = "tag_001_014_1846">&nbsp;</a>INPUT FILES</h4><blockquote>None.</blockquote><h4><a name = "tag_001_014_1847">&nbsp;</a>ENVIRONMENT VARIABLES</h4><blockquote>The following environment variables affect the execution of<i>read</i>:<dl compact><dt><i>IFS</i><dd>Determine the internal field separators used to delimit fields.See<xref href=shvars><a href="chap2.html#tag_001_005_003">Shell Variables</a></xref>.<dt><i>LANG</i><dd>Provide a default value for the internationalisation variablesthat are unset or null.If<i>LANG</i>is unset or null, the corresponding value from theimplementation-dependent default locale will be used.If any of the internationalisation variables contains an invalid setting, theutility will behave as if none of the variables had been defined.<dt><i>LC_ALL</i><dd>If set to a non-empty string value,override the values of all the other internationalisation variables.<dt><i>LC_CTYPE</i><dd>Determine thelocale for the interpretation of sequences of bytes of text data ascharacters (for example, single- as opposed to multi-byte charactersin arguments).<dt><i>LC_MESSAGES</i><dd>Determine the locale that should be used to affectthe format and contents of diagnosticmessages written to standard error.<dt><i>NLSPATH</i><dd>Determine the location of message cataloguesfor the processing of<i>LC_MESSAGES .</i><dt><i>PS2</i><dd>Provide theprompt string that an interactive shellwill write to standard error when aline ending with a backslash is read and the<b>-r</b>option was not specified,or if a here-document is not terminated after anewline characteris entered.</dl></blockquote><h4><a name = "tag_001_014_1848">&nbsp;</a>ASYNCHRONOUS EVENTS</h4><blockquote>Default.</blockquote><h4><a name = "tag_001_014_1849">&nbsp;</a>STDOUT</h4><blockquote>Not used.</blockquote><h4><a name = "tag_001_014_1850">&nbsp;</a>STDERR</h4><blockquote>Used for diagnostic messages and prompts for continued input.</blockquote><h4><a name = "tag_001_014_1851">&nbsp;</a>OUTPUT FILES</h4><blockquote>None.</blockquote><h4><a name = "tag_001_014_1852">&nbsp;</a>EXTENDED DESCRIPTION</h4><blockquote>None.</blockquote><h4><a name = "tag_001_014_1853">&nbsp;</a>EXIT STATUS</h4><blockquote>The following exit values are returned:<dl compact><dt>0<dd>Successful completion.<dt>&gt;0<dd>End-of-file was detected or an error occurred.</dl></blockquote><h4><a name = "tag_001_014_1854">&nbsp;</a>CONSEQUENCES OF ERRORS</h4><blockquote>Default.</blockquote><h4><a name = "tag_001_014_1855">&nbsp;</a>APPLICATION USAGE</h4><blockquote>The<i>read</i>utility has historically been a shell built-in.<p>The<b>-r</b>option is included to enable<i>read</i>to subsume the purpose of the<i><a href="line.html">line</a></i>utility, which has been marked LEGACY.<p>The results are undefined if an end-of-fileis detected following a backslash at the end of a line when<b>-r</b>is not specified.</blockquote><h4><a name = "tag_001_014_1856">&nbsp;</a>EXAMPLES</h4><blockquote>The following command:<pre><code>while read -r xx yydo	printf "%s %s\n" "$yy" "$xx"done &lt; <i>input_file</i></code></pre>prints a file with the first field of each line movedto the end of the line.</blockquote><h4><a name = "tag_001_014_1857">&nbsp;</a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_001_014_1858">&nbsp;</a>SEE ALSO</h4><blockquote>None.</blockquote><hr size=2 noshade><center><font size=2>UNIX &reg; is a registered Trademark of The Open Group.<br>Copyright &copy; 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>

⌨️ 快捷键说明

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