📄 ed.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>ed</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="ed"></a> <a name="tag_04_42"></a><!-- ed --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright © 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_04_42_01"></a>NAME</h4><blockquote>ed - edit text</blockquote><h4><a name="tag_04_42_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>ed</tt> <b>[</b><tt>-p</tt> <i>string</i><b>][</b><tt>-s</tt><b>][</b><i>file</i><b>]</b></code></p></blockquote><h4><a name="tag_04_42_03"></a>DESCRIPTION</h4><blockquote><p>The <i>ed</i> utility is a line-oriented text editor that uses two modes: <i>command mode</i> and <i>input mode</i>. In commandmode the input characters shall be interpreted as commands, and in input mode they shall be interpreted as text. See the EXTENDEDDESCRIPTION section.</p></blockquote><h4><a name="tag_04_42_04"></a>OPTIONS</h4><blockquote><p>The <i>ed</i> utility shall conform to the Base Definitions volume of IEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap12.html#tag_12_02">Section 12.2, Utility Syntax Guidelines</a>.</p><p>The following options shall be supported:</p><dl compact><dt><b>-p </b> <i>string</i></dt><dd>Use <i>string</i> as the prompt string when in command mode. By default, there shall be no prompt string.</dd><dt><b>-s</b></dt><dd>Suppress the writing of byte counts by <b>e</b>, <b>E</b>, <b>r</b>, and <b>w</b> commands and of the <tt>'!'</tt> prompt aftera !<i>command</i>.</dd></dl></blockquote><h4><a name="tag_04_42_05"></a>OPERANDS</h4><blockquote><p>The following operand shall be supported:</p><dl compact><dt><i>file</i></dt><dd>If the <i>file</i> argument is given, <i>ed</i> shall simulate an <b>e</b> command on the file named by the pathname,<i>file</i>, before accepting commands from the standard input. If the <i>file</i> operand is <tt>'-'</tt> , the results areunspecified.</dd></dl></blockquote><h4><a name="tag_04_42_06"></a>STDIN</h4><blockquote><p>The standard input shall be a text file consisting of commands, as described in the EXTENDED DESCRIPTION section.</p></blockquote><h4><a name="tag_04_42_07"></a>INPUT FILES</h4><blockquote><p>The input files shall be text files.</p></blockquote><h4><a name="tag_04_42_08"></a>ENVIRONMENT VARIABLES</h4><blockquote><p>The following environment variables shall affect the execution of <i>ed</i>:</p><dl compact><dt><i>HOME</i></dt><dd>Determine the pathname of the user's home directory.</dd><dt><i>LANG</i></dt><dd>Provide a default value for the internationalization variables that are unset or null. (See the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap08.html#tag_08_02">Section 8.2, Internationalization Variables</a> forthe precedence of internationalization variables used to determine the values of locale categories.)</dd><dt><i>LC_ALL</i></dt><dd>If set to a non-empty string value, override the values of all the other internationalization variables.</dd><dt><i>LC_COLLATE</i></dt><dd><br>Determine the locale for the behavior of ranges, equivalence classes, and multi-character collating elements within regularexpressions.</dd><dt><i>LC_CTYPE</i></dt><dd>Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single-byte asopposed to multi-byte characters in arguments and input files) and the behavior of character classes within regularexpressions.</dd><dt><i>LC_MESSAGES</i></dt><dd>Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error andinformative messages written to standard output.</dd><dt><i>NLSPATH</i></dt><dd><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">Determine the location of message catalogs for the processing of <i>LC_MESSAGES .</i> <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd></dl></blockquote><h4><a name="tag_04_42_09"></a>ASYNCHRONOUS EVENTS</h4><blockquote><p>The <i>ed</i> utility shall take the standard action for all signals (see the ASYNCHRONOUS EVENTS section in <a href="xcu_chap01.html#tag_01_11"><i>Utility Description Defaults</i></a> ) with the following exceptions:</p><dl compact><dt>SIGINT</dt><dd>The <i>ed</i> utility shall interrupt its current activity, write the string <tt>"?\n"</tt> to standard output, and return tocommand mode (see the EXTENDED DESCRIPTION section).</dd><dt>SIGHUP</dt><dd>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 in a file. First, the file named <b>ed.hup</b> in the current directory shall be used; if that fails, the file named<b>ed.hup</b> in the directory named by the <i>HOME</i> environment variable shall be used. In any case, the <i>ed</i> utilityshall exit without returning to command mode.</dd><dt>SIGQUIT</dt><dd>The <i>ed</i> utility shall ignore this event.</dd></dl></blockquote><h4><a name="tag_04_42_10"></a>STDOUT</h4><blockquote><p>Various editing commands and the prompting feature (see <b>-p</b>) write to standard output, as described in the EXTENDEDDESCRIPTION section.</p></blockquote><h4><a name="tag_04_42_11"></a>STDERR</h4><blockquote><p>The standard error shall be used only for diagnostic messages.</p></blockquote><h4><a name="tag_04_42_12"></a>OUTPUT FILES</h4><blockquote><p>The output files shall be text files whose formats are dependent on the editing commands given.</p></blockquote><h4><a name="tag_04_42_13"></a>EXTENDED DESCRIPTION</h4><blockquote><p>The <i>ed</i> utility shall operate on a copy of the file it is editing; changes made to the copy shall have no effect on thefile until a <b>w</b> (write) command is given. The copy of the text is called the <i>buffer</i>.</p><p>Commands to <i>ed</i> have a simple and regular structure: zero, one, or two <i>addresses</i> followed by a single-character<i>command</i>, possibly followed by parameters to that command. These addresses specify one or more lines in the buffer. Everycommand that requires addresses has default addresses, so that the addresses very often can be omitted. If the <b>-p</b> option isspecified, the prompt string shall be written to standard output before each command is read.</p><p>In general, only one command can appear on a line. Certain commands allow text to be input. This text is placed in theappropriate place in the buffer. While <i>ed</i> is accepting text, it is said to be in <i>input mode</i>. In this mode, nocommands shall be recognized; all input is merely collected. Input mode is terminated by entering a line consisting of twocharacters: a period ( <tt>'.'</tt> ) followed by a <newline>. This line is not considered part of the input text.</p><h5><a name="tag_04_42_13_01"></a>Regular Expressions in ed</h5><p>The <i>ed</i> utility shall support basic regular expressions, as described in the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap09.html#tag_09_03">Section 9.3, Basic Regular Expressions</a>. Sinceregular expressions in <i>ed</i> are always matched against single lines (excluding the terminating <newline>s), neveragainst any larger section of text, there is no way for a regular expression to match a <newline>.</p><p>A null RE shall be equivalent to the last RE encountered.</p><p>Regular expressions are used in addresses to specify lines, and in some commands (for example, the <b>s</b> substitute command)to specify portions of a line to be substituted.</p><h5><a name="tag_04_42_13_02"></a>Addresses in ed</h5><p>Addressing in <i>ed</i> relates to the current line. Generally, the current line is the last line affected by a command. Thecurrent line number is the address of the current line. If the edit buffer is not empty, the initial value for the current lineshall be the last line in the edit buffer; otherwise, zero.</p><p>Addresses shall be constructed as follows:</p><ol><li><p>The period character ( <tt>'.'</tt> ) shall address the current line.</p></li><li><p>The dollar sign character ( <tt>'$'</tt> ) shall address the last line of the edit buffer.</p></li><li><p>The positive decimal number <i>n</i> shall address the <i>n</i>th line of the edit buffer.</p></li><li><p>The apostrophe-x character pair ( <tt>"'x"</tt> ) shall address the line marked with the mark name character <i>x</i>, whichshall be a lowercase letter from the portable character set. It shall be an error if the character has not been set to mark a lineor if the line that was marked is not currently present in the edit buffer.</p></li><li><p>A BRE enclosed by slash characters ( <tt>'/'</tt> ) shall address the first line found by searching forwards from the linefollowing the current line toward the end of the edit buffer and stopping at the first line for which the line excluding theterminating <newline> matches the BRE. The BRE consisting of a null BRE delimited by a pair of slash characters shall addressthe next line for which the line excluding the terminating <newline> matches the last BRE encountered. In addition, thesecond slash can be omitted at the end of a command line. Within the BRE, a backslash-slash pair ( <tt>"\/"</tt> ) shall representa literal slash instead of the BRE delimiter. If necessary, the search shall wrap around to the beginning of the buffer andcontinue up to and including the current line, so that the entire buffer is searched.</p></li><li><p>A BRE enclosed by question-mark characters ( <tt>'?'</tt> ) shall address the first line found by searching backwards from theline preceding the current line toward the beginning of the edit buffer and stopping at the first line for which the line excludingthe terminating <newline> matches the BRE. The BRE consisting of a null BRE delimited by a pair of question-mark characters (<tt>"??"</tt> ) shall address the previous line for which the line excluding the terminating <newline> matches the last BREencountered. In addition, the second question-mark can be omitted at the end of a command line. Within the BRE, abackslash-question-mark pair ( <tt>"\?"</tt> ) shall represent a literal question mark instead of the BRE delimiter. If necessary,the search shall wrap around to the end of the buffer and continue up to and including the current line, so that the entire bufferis searched.</p></li><li><p>A plus-sign ( <tt>'+'</tt> ) or hyphen character ( <tt>'-'</tt> ) followed by a decimal number shall address the current lineplus or minus the number. A plus-sign or hyphen character not followed by a decimal number shall address the current line plus orminus 1.</p></li></ol><p>Addresses can be followed by zero or more address offsets, optionally <blank>-separated. Address offsets are constructedas follows:</p><ul><li><p>A plus-sign or hyphen character followed by a decimal number shall add or subtract, respectively, the indicated number of linesto or from the address. A plus-sign or hyphen character not followed by a decimal number shall add or subtract 1 to or from theaddress.</p></li><li><p>A decimal number shall add the indicated number of lines to the address.</p></li></ul><p>It shall not be an error for an intermediate address value to be less than zero or greater than the last line in the editbuffer. It shall be an error for the final address value to be less than zero or greater than the last line in the edit buffer. Itshall be an error if a search for a BRE fails to find a matching line.</p><p>Commands accept zero, one, or two addresses. If more than the required number of addresses are provided to a command thatrequires zero addresses, it shall be an error. Otherwise, if more than the required number of addresses are provided to a command,the addresses specified first shall be evaluated and then discarded until the maximum number of valid addresses remain, for thespecified command.</p><p>Addresses shall be separated from each other by a comma ( <tt>','</tt> ) or semicolon character ( <tt>';'</tt> ). In the case ofa semicolon separator, the current line ( <tt>'.'</tt> ) shall be set to the first address, and only then will the second addressbe calculated. This feature can be used to determine the starting line for forwards and backwards searches; see rules 5. and 6.</p><p>Addresses can be omitted on either side of the comma or semicolon separator, in which case the resulting address pairs shall beas follows:</p><center><table border="1" cellpadding="3" align="center"><tr valign="top"><th align="center"><p class="tent"><b>Specified</b></p></th><th align="center"><p class="tent"><b>Resulting</b></p></th></tr><tr valign="top"><td align="left"><p class="tent">,</p></td><td align="left"><p class="tent">1 , $</p></td></tr><tr valign="top"><td align="left"><p class="tent">, addr</p></td><td align="left"><p class="tent">1 , addr</p></td></tr><tr valign="top"><td align="left"><p class="tent">addr ,</p></td><td align="left"><p class="tent">addr , addr</p></td></tr><tr valign="top"><td align="left"><p class="tent">;</p></td><td align="left"><p class="tent">. ; $</p></td></tr><tr valign="top"><td align="left"><p class="tent">; addr</p></td><td align="left"><p class="tent">. ; addr</p></td></tr><tr valign="top"><td align="left"><p class="tent">addr ;</p></td><td align="left"><p class="tent">addr ; addr</p></td>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -