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

📄 ed.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 HTML
📖 第 1 页 / 共 5 页
字号:
</tr></table></center><p>Any &lt;blank&gt;s included between addresses, address separators, or address offsets shall be ignored.</p><h5><a name="tag_04_42_13_03"></a>Commands in ed</h5><p>In the following list of <i>ed</i> commands, the default addresses are shown in parentheses. The number of addresses shown inthe default shall be the number expected by the command. The parentheses are not part of the address; they show that the givenaddresses are the default.</p><p>It is generally invalid for more than one command to appear on a line. However, any command (except <b>e</b>, <b>E</b>,<b>f</b>, <b>q</b>, <b>Q</b>, <b>r</b>, <b>w</b>, and <b>!</b>) can be suffixed by the letter <b>l</b>, <b>n</b>, or <b>p</b>; inwhich case, except for the <b>l</b>, <b>n</b>, and <b>p</b> commands, the command shall be executed and then the new current lineshall be written as described below under the <b>l</b>, <b>n</b>, and <b>p</b> commands. When an <b>l</b>, <b>n</b>, or <b>p</b>suffix is used with an <b>l</b>, <b>n</b>, or <b>p</b> command, the command shall write to standard output as described below, butit is unspecified whether the suffix writes the current line again in the requested format or whether the suffix has no effect. Forexample, the <b>pl</b> command (base <b>p</b> command with an <b>l</b> suffix) shall either write just the current line or write ittwice-once as specified for <b>p</b> and once as specified for <b>l</b>. Also, the <b>g</b>, <b>G</b>, <b>v</b>, and <b>V</b>commands shall take a command as a parameter.</p><p>Each address component can be preceded by zero or more &lt;blank&gt;s. The command letter can be preceded by zero or more&lt;blank&gt;s. If a suffix letter ( <b>l</b>, <b>n</b>, or <b>p</b>) is given, the application shall ensure that it immediatelyfollows the command.</p><p>The <b>e</b>, <b>E</b>, <b>f</b>, <b>r</b>, and <b>w</b> commands shall take an optional <i>file</i> parameter, separated fromthe command letter by one or more &lt;blank&gt;s.</p><p>If changes have been made in the buffer since the last <b>w</b> command that wrote the entire buffer, <i>ed</i> shall warn theuser if an attempt is made to destroy the editor buffer via the <b>e</b> or <b>q</b> commands. The <i>ed</i> utility shall writethe string:</p><pre><tt>"?\n"</tt></pre><p>(followed by an explanatory message if <i>help mode</i> has been enabled via the <b>H</b> command) to standard output and shallcontinue in command mode with the current line number unchanged. If the <b>e</b> or <b>q</b> command is repeated with nointervening command, it shall take effect.</p><p>If a terminal disconnect is detected:</p><ul><li><p>If the buffer is not empty and has changed since the last write, the <i>ed</i> utility shall attempt to write a copy of thebuffer to a file named <b>ed.hup</b> in the current directory. If this write fails, <i>ed</i> shall attempt to write a copy of thebuffer to a filename <b>ed.hup</b> in the directory named by the <i>HOME</i> environment variable. If both these attempts fail,<i>ed</i> shall exit without saving the buffer.</p></li><li><p>The <i>ed</i> utility shall not write the file to the currently remembered pathname or return to command mode, and shallterminate with a non-zero exit status.</p></li></ul><p>If an end-of-file is detected on standard input:</p><ul><li><p>If the <i>ed</i> utility is in input mode, <i>ed</i> shall terminate input mode and return to command mode. It is unspecified ifany partially entered lines (that is, input text without a terminating &lt;newline&gt;) are discarded from the input text.</p></li><li><p>If the <i>ed</i> utility is in command mode, it shall act as if a <b>q</b> command had been entered.</p></li></ul><p>If the closing delimiter of an RE or of a replacement string (for example, <tt>'/'</tt> ) in a <b>g</b>, <b>G</b>, <b>s</b>,<b>v</b>, or <b>V</b> command would be the last character before a &lt;newline&gt;, that delimiter can be omitted, in which casethe addressed line shall be written. For example, the following pairs of commands are equivalent:</p><pre><tt>s/s1/s2   s/s1/s2/pg/s1      g/s1/p?s1       ?s1?</tt></pre><p>If an invalid command is entered, <i>ed</i> shall write the string:</p><pre><tt>"?\n"</tt></pre><p>(followed by an explanatory message if <i>help mode</i> has been enabled via the <b>H</b> command) to standard output and shallcontinue in command mode with the current line number unchanged.</p><h5><a name="tag_04_42_13_04"></a>Append Command</h5><dl compact><dt><i>Synopsis</i>:</dt><dd><pre><tt>(.)a&lt;</tt><i>text</i><tt>&gt;.</tt></pre></dd></dl><p>The <b>a</b> command shall read the given text and append it after the addressed line; the current line number shall become theaddress of the last inserted line or, if there were none, the addressed line. Address 0 shall be valid for this command; it shallcause the appended text to be placed at the beginning of the buffer.</p><h5><a name="tag_04_42_13_05"></a>Change Command</h5><dl compact><dt><i>Synopsis</i>:</dt><dd><pre><tt>(.,.)c&lt;</tt><i>text</i><tt>&gt;.</tt></pre></dd></dl><p>The <b>c</b> command shall delete the addressed lines, then accept input text that replaces these lines; the current line shallbe set to the address of the last line input; or, if there were none, at the line after the last line deleted; if the lines deletedwere originally at the end of the buffer, the current line number shall be set to the address of the new last line; if no linesremain in the buffer, the current line number shall be set to zero. Address 0 shall be valid for this command; it shall beinterpreted as if address 1 were specified.</p><h5><a name="tag_04_42_13_06"></a>Delete Command</h5><dl compact><dt><i>Synopsis</i>:</dt><dd><pre><tt>(.,.)d</tt></pre></dd></dl><p>The <b>d</b> command shall delete the addressed lines from the buffer. The address of the line after the last line deleted shallbecome the current line number; if the lines deleted were originally at the end of the buffer, the current line number shall be setto the address of the new last line; if no lines remain in the buffer, the current line number shall be set to zero.</p><h5><a name="tag_04_42_13_07"></a>Edit Command</h5><dl compact><dt><i>Synopsis</i>:</dt><dd><pre><tt>e</tt> <b>[</b><i>file</i><b>]</b></pre></dd></dl><p>The <b>e</b> command shall delete the entire contents of the buffer and then read in the file named by the pathname <i>file</i>.The current line number shall be set to the address of the last line of the buffer. If no pathname is given, the currentlyremembered pathname, if any, shall be used (see the <b>f</b> command). The number of bytes read shall be written to standardoutput, unless the <b>-s</b> option was specified, in the following format:</p><pre><tt>"%d\n", &lt;</tt><i>number of bytes read</i><tt>&gt;</tt></pre><p>The name <i>file</i> shall be remembered for possible use as a default pathname in subsequent <b>e</b>, <b>E</b>, <b>r</b>, and<b>w</b> commands. If <i>file</i> is replaced by <tt>'!'</tt> , the rest of the line shall be taken to be a shell command linewhose output is to be read. Such a shell command line shall not be remembered as the current <i>file</i>. All marks shall bediscarded upon the completion of a successful <b>e</b> command. If the buffer has changed since the last time the entire buffer waswritten, the user shall be warned, as described previously.</p><h5><a name="tag_04_42_13_08"></a>Edit Without Checking Command</h5><dl compact><dt><i>Synopsis</i>:</dt><dd><pre><tt>E</tt> <b>[</b><i>file</i><b>]</b></pre></dd></dl><p>The <b>E</b> command shall possess all properties and restrictions of the <b>e</b> command except that the editor shall notcheck to see whether any changes have been made to the buffer since the last <b>w</b> command.</p><h5><a name="tag_04_42_13_09"></a>Filename Command</h5><dl compact><dt><i>Synopsis</i>:</dt><dd><pre><tt>f</tt> <b>[</b><i>file</i><b>]</b></pre></dd></dl><p>If <i>file</i> is given, the <b>f</b> command shall change the currently remembered pathname to <i>file</i>; whether the name ischanged or not, it shall then write the (possibly new) currently remembered pathname to the standard output in the followingformat:</p><pre><tt>"%s\n", &lt;</tt><i>pathname</i><tt>&gt;</tt></pre><p>The current line number shall be unchanged.</p><h5><a name="tag_04_42_13_10"></a>Global Command</h5><dl compact><dt><i>Synopsis</i>:</dt><dd><pre><tt>(1,$)g/</tt><i>RE</i><tt>/</tt><i>command list</i></pre></dd></dl><p>In the <b>g</b> command, the first step shall be to mark every line for which the line excluding the terminating &lt;newline&gt;matches the given RE. Then, going sequentially from the beginning of the file to the end of the file, the given <i>command list</i>shall be executed for each marked line, with the current line number set to the address of that line. Any line modified by the<i>command list</i> shall be unmarked. When the <b>g</b> command completes, the current line number shall have the value assignedby the last command in the <i>command list</i>. If there were no matching lines, the current line number shall not be changed. Asingle command or the first of a list of commands shall appear on the same line as the global command. All lines of a multi-linelist except the last line shall be ended with a backslash preceding the terminating &lt;newline&gt;; the <b>a</b>, <b>i</b>, and<b>c</b> commands and associated input are permitted. The <tt>'.'</tt> terminating input mode can be omitted if it would be thelast line of the <i>command list</i>. An empty <i>command list</i> shall be equivalent to the <b>p</b> command. The use of the<b>g</b>, <b>G</b>, <b>v</b>, <b>V</b>, and <b>!</b> commands in the <i>command list</i> produces undefined results. Any characterother than &lt;space&gt; or &lt;newline&gt; can be used instead of a slash to delimit the RE. Within the RE, the RE delimiteritself can be used as a literal character if it is preceded by a backslash.</p><h5><a name="tag_04_42_13_11"></a>Interactive Global Command</h5><dl compact><dt><i>Synopsis</i>:</dt><dd><pre><tt>(1,$)G/</tt><i>RE</i><tt>/</tt></pre></dd></dl><p>In the <b>G</b> command, the first step shall be to mark every line for which the line excluding the terminating &lt;newline&gt;matches the given RE. Then, for every such line, that line shall be written, the current line number shall be set to the address ofthat line, and any one command (other than one of the <b>a</b>, <b>c</b>, <b>i</b>, <b>g</b>, <b>G</b>, <b>v</b>, and <b>V</b>commands) shall be read and executed. A &lt;newline&gt; shall act as a null command (causing no action to be taken on the currentline); an <tt>'&amp;'</tt> shall cause the re-execution of the most recent non-null command executed within the current invocationof <b>G</b>. Note that the commands input as part of the execution of the <b>G</b> command can address and affect any lines in thebuffer. Any line modified by the command shall be unmarked. The final value of the current line number shall be the value set bythe last command successfully executed. (Note that the last command successfully executed shall be the <b>G</b> command itself if acommand fails or the null command is specified.) If there were no matching lines, the current line number shall not be changed. The<b>G</b> command can be terminated by a SIGINT signal. Any character other than &lt;space&gt; or &lt;newline&gt; can be usedinstead of a slash to delimit the RE and the replacement. Within the RE, the RE delimiter itself can be used as a literal characterif it is preceded by a backslash.</p><h5><a name="tag_04_42_13_12"></a>Help Command</h5><dl compact><dt><i>Synopsis</i>:</dt><dd><pre><tt>h</tt></pre></dd></dl><p>The <b>h</b> command shall write a short message to standard output that explains the reason for the most recent <tt>'?'</tt>notification. The current line number shall be unchanged.</p><h5><a name="tag_04_42_13_13"></a>Help-Mode Command</h5><dl compact><dt><i>Synopsis</i>:</dt><dd><pre><tt>H</tt></pre></dd></dl><p>The <b>H</b> command shall cause <i>ed</i> to enter a mode in which help messages (see the <b>h</b> command) shall be written tostandard output for all subsequent <tt>'?'</tt> notifications. The <b>H</b> command alternately shall turn this mode on and off; itis initially off. If the help-mode is being turned on, the <b>H</b> command also explains the previous <tt>'?'</tt> notification,if there was one. The current line number shall be unchanged.</p><h5><a name="tag_04_42_13_14"></a>Insert Command</h5><dl compact><dt><i>Synopsis</i>:</dt><dd><pre><tt>(.)i&lt;</tt><i>text</i><tt>&gt;.</tt></pre></dd></dl><p>The <b>i</b> command shall insert the given text before the addressed line; the current line is set to the last inserted lineor, if there was none, to the addressed line. This command differs from the <b>a</b> command only in the placement of the inputtext. Address 0 shall be valid for this command; it shall be interpreted as if address 1 were specified.</p><h5><a name="tag_04_42_13_15"></a>Join Command</h5><dl compact><dt><i>Synopsis</i>:</dt><dd><pre><tt>(.,.+1)j</tt></pre></dd></dl><p>The <b>j</b> command shall join contiguous lines by removing the appropriate &lt;newline&gt;s. If exactly one address is given,this command shall do nothing. If lines are joined, the current line number shall be set to the address of the joined line;otherwise, the current line number shall be unchanged.</p><h5><a name="tag_04_42_13_16"></a>Mark Command</h5><dl compact><dt><i>Synopsis</i>:</dt><dd><pre><tt>(.)k</tt><i>x</i></pre></dd></dl><p>The <b>k</b> command shall mark the addressed line with name <i>x</i>, which the application shall ensure is a lowercase letterfrom the portable character set. The address <tt>"'x"</tt> shall then refer to this line; the current line number shall beunchanged.</p>

⌨️ 快捷键说明

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