1 '\" te 2 .\" Copyright 1989 AT&T Copyright (c) 2003, Sun Microsystems, Inc. Portions Copyright (c) 1992, X/Open Company Limited All Rights Reserved 3 .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at 4 .\" http://www.opengroup.org/bookstore/. 5 .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html. 6 .\" This notice shall appear on any product containing this material. 7 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. 8 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. 9 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] 10 .TH ED 1 "Dec 10, 2003" 11 .SH NAME 12 ed, red \- text editor 13 .SH SYNOPSIS 14 .LP 15 .nf 16 \fB/usr/bin/ed\fR [\fB-s\fR | \fB-\fR] [\fB-p\fR \fIstring\fR] [\fB-x\fR] [\fB-C\fR] [\fIfile\fR] 17 .fi 18 19 .LP 20 .nf 21 \fB/usr/xpg4/bin/ed\fR [\fB-s\fR | \fB-\fR] [\fB-p\fR \fIstring\fR] [\fB-x\fR] [\fB-C\fR] [\fIfile\fR] 22 .fi 23 24 .LP 25 .nf 26 \fB/usr/xpg6/bin/ed\fR [\fB-s\fR | \fB-\fR] [\fB-p\fR \fIstring\fR] [\fB-x\fR] [\fB-C\fR] [\fIfile\fR] 27 .fi 28 29 .LP 30 .nf 31 \fB/usr/bin/red\fR [\fB-s\fR | \fB-\fR] [\fB-p\fR \fIstring\fR] [\fB-x\fR] [\fB-C\fR] [\fIfile\fR] 32 .fi 33 34 .SH DESCRIPTION 35 .sp 36 .LP 37 The \fBed\fR utility is the standard text editor. If \fIfile\fR is specified, 38 \fBed\fR simulates an \fBe\fR command (see below) on the named file. That is, 39 the file is read into \fBed\fR's buffer so that it can be edited. 40 .sp 41 .LP 42 The \fBed\fR utility operates on a copy of the file it is editing. Changes made 43 to the copy have no effect on the file until a \fBw\fR (write) command is 44 given. The copy of the text being edited resides in a temporary file called the 45 \fIbuffer\fR. There is only one buffer. 46 .sp 47 .LP 48 The \fBred\fR utility is a restricted version of \fBed\fR. It will only allow 49 editing of files in the current directory. \fBred\fR prohibits executing shell 50 commands via \fB!\fR\fIshell command\fR. Attempts to bypass these restrictions 51 result in an error message (\fIrestricted shell\fR). 52 .sp 53 .LP 54 Both \fBed\fR and \fBred\fR support the \fBfspec\fR(4) formatting capability. 55 The default terminal mode is either \fBstty\fR \fB-tabs\fR or \fBstty tab3\fR, 56 where tab stops are set at eight columns (see \fBstty\fR(1)). If, however, the 57 first line of \fIfile\fR contains a format specification, that specification 58 will override the default mode. For example, tab stops would be set at 5, 10, 59 and 15, and a maximum line length of 72 would be imposed if the first line of 60 \fIfile\fR contains 61 .sp 62 .in +2 63 .nf 64 \fB<:t5,10,15 s72:>\fR 65 .fi 66 .in -2 67 .sp 68 69 .sp 70 .LP 71 Commands to \fBed\fR have a simple and regular structure: zero, one, or two 72 \fIaddresses\fR followed by a single-character \fIcommand\fR, possibly followed 73 by parameters to that command. These addresses specify one or more lines in the 74 buffer. Every command that requires addresses has default addresses, so that 75 the addresses can very often be omitted. 76 .sp 77 .LP 78 In general, only one command may appear on a line. Certain commands allow the 79 input of text. This text is placed in the appropriate place in the buffer. 80 While \fBed\fR is accepting text, it is said to be in \fIinput mode\fR. In this 81 mode, \fBno\fR commands are recognized; all input is merely collected. Leave 82 input mode by typing a period (\fB\&.\fR) at the beginning of a line, followed 83 immediately by a carriage return. 84 .sp 85 .LP 86 If \fBed\fR executes commands with arguments, it uses the default shell 87 \fB/usr/bin/sh\fR (see \fBsh\fR(1)). 88 .SS "Regular Expressions" 89 .sp 90 .LP 91 The \fBed\fR utility supports a limited form of \fIregular expression\fR 92 notation. Regular expressions are used in addresses to specify lines and in 93 some commands (for example, \fBs\fR) to specify portions of a line that are to 94 be substituted. To understand addressing in \fBed\fR, it is necessary to know 95 that at any time there is a \fIcurrent line\fR. Generally speaking, the current 96 line is the last line affected by a command. The exact effect on the current 97 line is discussed under the description of each command. 98 .sp 99 .LP 100 Internationalized Basic Regular Expressions are used for all system-supplied 101 locales. See \fBregex\fR(5). 102 .SS "ed Commands" 103 .sp 104 .LP 105 Commands may require zero, one, or two addresses. Commands that require no 106 addresses regard the presence of an address as an error. Commands that accept 107 one or two addresses assume default addresses when an insufficient number of 108 addresses is given; if more addresses are given than such a command requires, 109 the last one(s) are used. 110 .sp 111 .LP 112 Typically, addresses are separated from each other by a comma (\fB,\fR). They 113 may also be separated by a semicolon (\fB;\fR). In the latter case, the first 114 address is calculated, the current line (\fB\&.\fR) is set to that value, and 115 then the second address is calculated. This feature can be used to determine 116 the starting line for forward and backward searches (see Rules 5 and 6, above). 117 The second address of any two-address sequence must correspond to a line in the 118 buffer that follows the line corresponding to the first address. 119 .sp 120 .LP 121 For \fB/usr/xpg6/gbin/ed\fR, the address can be omitted on either side of the 122 comma or semicolon separator, in which case the resulting address pairs are as 123 follows: 124 .sp 125 126 .sp 127 .TS 128 box; 129 c | c 130 l | l . 131 Specified Resulting 132 _ 133 , 1 , $ 134 _ 135 , addr 1 , addr 136 _ 137 addr , addr , addr 138 _ 139 ; 1 ; $ 140 _ 141 ; addr 1 ; addr 142 _ 143 addr ; addr ; addr 144 .TE 145 146 .sp 147 .LP 148 Any <\fIblank\fR>s included between addresses, address separators, or address 149 offsets are ignored. 150 .sp 151 .LP 152 In the following list of \fBed\fR commands, the parentheses shown prior to the 153 command are \fInot\fR part of the address. Rather, the parentheses show the 154 default address(es) for the command. 155 .sp 156 .LP 157 Each address component can be preceded by zero or more blank characters. The 158 command letter can be preceded by zero or more blank characters. If a suffix 159 letter (\fBl\fR, \fBn\fR, or \fBp\fR) is given, it must immediately follow the 160 command. 161 .sp 162 .LP 163 The \fBe\fR, \fBE\fR, \fBf\fR, \fBr\fR, and \fBw\fR commands take an optional 164 \fIfile\fR parameter, separated from the command letter by one or more blank 165 characters. 166 .sp 167 .LP 168 If changes have been made in the buffer since the last \fBw\fR command that 169 wrote the entire buffer, \fBed\fR warns the user if an attempt is made to 170 destroy the editor buffer via the \fBe\fR or \fBq\fR commands. The \fBed\fR 171 utility writes the string: 172 .sp 173 .in +2 174 .nf 175 "?\en" 176 .fi 177 .in -2 178 .sp 179 180 .sp 181 .LP 182 (followed by an explanatory message if \fIhelp mode\fR has been enabled via the 183 \fBH\fR command) to standard output and continues in command mode with the 184 current line number unchanged. If the \fBe\fR or \fBq\fR command is repeated 185 with no intervening command, \fBed\fR takes effect. 186 .sp 187 .LP 188 If an end-of-file is detected on standard input when a command is expected, the 189 \fBed\fR utility acts as if a \fBq\fR command had been entered. 190 .sp 191 .LP 192 It is generally illegal for more than one command to appear on a line. However, 193 any command (except \fBe\fR, \fBf\fR, \fBr\fR, or \fBw\fR) may be suffixed by 194 \fBl\fR, \fBn\fR, or \fBp\fR in which case the current line is either listed, 195 numbered or written, respectively, as discussed below under the \fBl\fR, 196 \fBn\fR, and \fBp\fR commands. 197 .sp 198 .ne 2 199 .na 200 \fB\fB(.)a\fR\fR 201 .ad 202 .br 203 .na 204 \fB<\fItext\fR> \fR 205 .ad 206 .br 207 .na 208 \fB\fB\&.\fR\fR 209 .ad 210 .RS 11n 211 The \fBa\fRppend command accepts zero or more lines of text and appends it 212 after the addressed line in the buffer. The current line (\fB\&.\fR) is left at 213 the last inserted line, or, if there were none, at the addressed line. Address 214 0 is legal for this command: it causes the ``appended'' text to be placed at 215 the beginning of the buffer. The maximum number of characters that may be 216 entered from a terminal is 256 per line (including the new-line character). 217 .RE 218 219 .sp 220 .ne 2 221 .na 222 \fB\fB(.,.)c\fR\fR 223 .ad 224 .br 225 .na 226 \fB<\fItext\fR>\fR 227 .ad 228 .br 229 .na 230 \fB\fB\&.\fR\fR 231 .ad 232 .RS 11n 233 The \fBc\fRhange command deletes the addressed lines from the buffer, then 234 accepts zero or more lines of text that replaces these lines in the buffer. The 235 current line (\fB\&.\fR) is left at the last line input, or, if there were 236 none, at the first line that was not deleted. If the lines deleted were 237 originally at the end of the buffer, the current line number will be set to the 238 address of the new last line. If no lines remain in the buffer, the current 239 line number will be set to 0. 240 .sp 241 .ne 2 242 .na 243 \fB\fB/usr/xpg4/bin/ed\fR\fR 244 .ad 245 .RS 20n 246 Address 0 is not legal for this command. 247 .RE 248 249 .sp 250 .ne 2 251 .na 252 \fB\fB/usr/xpg6/bin/ed\fR\fR 253 .ad 254 .RS 20n 255 Address 0 is valid for this command. It is interpreted as if the address 1 were 256 specified. 257 .RE 258 259 .RE 260 261 .sp 262 .ne 2 263 .na 264 \fB\fBC\fR\fR 265 .ad 266 .RS 11n 267 Same as the \fBX\fR command, described later, except that \fBed\fR assumes all 268 text read in for the \fBe\fR and \fBr\fR commands is encrypted unless a null 269 key is typed in. 270 .RE 271 272 .sp 273 .ne 2 274 .na 275 \fB\fB(.,.)d\fR\fR 276 .ad 277 .RS 11n 278 The \fBd\fRelete command deletes the addressed lines from the buffer. The line 279 after the last line deleted becomes the current line. If the lines deleted were 280 originally at the end of the buffer, the new last line becomes the current 281 line. If no lines remain in the buffer, the current line number will be set to 282 0. 283 .RE 284 285 .sp 286 .ne 2 287 .na 288 \fB\fBe\fR \fIfile\fR\fR 289 .ad 290 .RS 11n 291 The \fBe\fRdit command deletes the entire contents of the buffer and then reads 292 the contents of \fIfile\fR into the buffer. The current line (\fB\&.\fR) is set 293 to the last line of the buffer. If \fIfile\fR is not given, the currently 294 remembered file name, if any, is used (see the \fBf\fR command). The number of 295 bytes read will be written to standard output, unless the \fB-s\fR option was 296 specified, in the following format: 297 .sp 298 \fB"%d\en"\fR <\fInumber of bytes read\fR> 299 .sp 300 \fIfile\fR is remembered for possible use as a default file name in subsequent 301 \fBe\fR, \fBE\fR, \fBr\fR, and \fBw\fR commands. If \fIfile\fR is replaced by 302 \fB!\fR, the rest of the line is taken to be a shell ( \fBsh\fR(1)) command 303 whose output is to be read. Such a shell command is \fInot\fR remembered as the 304 current file name. See also DIAGNOSTICS below. All marks are discarded upon 305 the completion of a successful \fBe\fR command. If the buffer has changed since 306 the last time the entire buffer was written, the user is warned, as described 307 previously. 308 .RE 309 310 .sp 311 .ne 2 312 .na 313 \fB\fBE\fR \fIfile\fR\fR 314 .ad 315 .RS 11n 316 The \fBE\fRdit command is like \fBe\fR, except that the editor does not check 317 to see if any changes have been made to the buffer since the last \fBw\fR 318 command. 319 .RE 320 321 .sp 322 .ne 2 323 .na 324 \fB\fBf\fR \fIfile\fR\fR 325 .ad 326 .RS 11n 327 If \fIfile\fR is given, the \fBf\fR command changes the currently remembered 328 path name to \fIfile\fR. Whether the name is changed or not, the \fBf\fR 329 command then writes the (possibly new) currently remembered path name to the 330 standard output in the following format: 331 .sp 332 \fB"%s\en"\fR\fIpathname\fR 333 .sp 334 The current line number is unchanged. 335 .RE 336 337 .sp 338 .ne 2 339 .na 340 \fB\fB(1,$)g/\fR\fIRE\fR\fB/\fR\fIcommand list\fR\fR 341 .ad 342 .RS 26n 343 In the \fBg\fRlobal command, the first step is to mark every line that matches 344 the given \fIRE\fR. Then, for every such line, the given \fIcommand list\fR is 345 executed with the current line (\fB\&.\fR) initially set to that line. When the 346 \fBg\fR command completes, the current line number has the value assigned by 347 the last command in the command list. If there were no matching lines, the 348 current line number is not changed. A single command or the first of a list of 349 commands appears on the same line as the global command. All lines of a 350 multi-line list except the last line must be ended with a backslash 351 (\fB\e\fR\|); \fBa\fR, \fBi\fR, and \fBc\fR commands and associated input are 352 permitted. The \fB\&.\fR terminating input mode may be omitted if it would be 353 the last line of the \fIcommand list\fR. An empty \fIcommand list\fR is 354 equivalent to the \fBp\fR command. The \fBg\fR, \fBG\fR, \fBv\fR, \fBV\fR, and 355 \fB!\fR commands are \fInot\fR permitted in the \fIcommand list\fR. See also 356 the NOTES and the last paragraph before FILES below. Any character other than 357 space or newline can be used instead of a slash to delimit the \fIRE\fR. Within 358 the \fIRE\fR, the \fIRE\fR delimiter itself can be used as a literal character 359 if it is preceded by a backslash. 360 .RE 361 362 .sp 363 .ne 2 364 .na 365 \fB\fB(1,$)G/\fR\fIRE\fR\fB/\fR\fR 366 .ad 367 .RS 26n 368 In the interactive \fBG\fRlobal command, the first step is to mark every line 369 that matches the given \fIRE\fR. Then, for every such line, that line is 370 written to standard output, the current line (\fB\&.\fR) is changed to that 371 line, and any \fIone\fR command (other than one of the \fBa\fR, \fBc\fR, 372 \fBi\fR, \fBg\fR, \fBG\fR, \fBv\fR, and \fBV\fR commands) may be input and is 373 executed. After the execution of that command, the next marked line is written, 374 and so on. A new-line acts as a null command. An \fB&\fR causes the 375 re-execution of the most recent non-null command executed within the current 376 invocation of \fBG\fR. \fBNote:\fR The commands input as part of the execution 377 of the \fBG\fR command may address and affect \fBany\fR lines in the buffer. 378 The final value of the current line number is the value set by the last command 379 successfully executed. (Notice that the last command successfully executed is 380 the \fBG\fR command itself if a command fails or the null command is 381 specified.) If there were no matching lines, the current line number is not 382 changed. The \fBG\fR command can be terminated by a \fBSIGINT\fR signal. The 383 \fBG\fR command can be terminated by an interrupt signal (ASCII DEL or BREAK). 384 Any character other than space or newline can be used instead of a slash to 385 delimit the \fIRE\fR. Within the \fIRE\fR, the \fIRE\fR delimiter itself can be 386 used as a literal character if it is preceded by a backslash. 387 .RE 388 389 .sp 390 .ne 2 391 .na 392 \fB\fBh\fR\fR 393 .ad 394 .RS 26n 395 The \fBhelp\fR command gives a short error message that explains the reason for 396 the most recent \fB?\fR diagnostic. The current line number is unchanged. 397 .RE 398 399 .sp 400 .ne 2 401 .na 402 \fB\fBH\fR\fR 403 .ad 404 .RS 26n 405 The \fBHelp\fR command causes \fBed\fR to enter a mode in which error messages 406 are written for all subsequent \fB?\fR diagnostics. It also explains the 407 previous \fB?\fR if there was one. The \fBH\fR command alternately turns this 408 mode on and off; it is initially off. The current line number is unchanged. 409 .RE 410 411 .sp 412 .ne 2 413 .na 414 \fB\fB(.,.)i\fR\fR 415 .ad 416 .br 417 .na 418 \fB<\fItext\fR>\fR 419 .ad 420 .br 421 .na 422 \fB\fB\&.\fR\fR 423 .ad 424 .RS 26n 425 The \fBinsert\fR command accepts zero or more lines of text and inserts it 426 before the addressed line in the buffer. The current line (\fB\&.\fR) is left 427 at the last inserted line, or, if there were none, at the addressed line. This 428 command differs from the \fBa\fR command only in the placement of the input 429 text. The maximum number of characters that may be entered from a terminal is 430 256 per line (including the new-line character). 431 .sp 432 .ne 2 433 .na 434 \fB\fB/usr/xpg4/bin/ed\fR\fR 435 .ad 436 .RS 20n 437 Address 0 is not legal for this command. 438 .RE 439 440 .sp 441 .ne 2 442 .na 443 \fB\fB/usr/xpg6/bin/ed\fR\fR 444 .ad 445 .RS 20n 446 Address 0 is valid for this command. It is interpreted as if the address 1 were 447 specified. 448 .RE 449 450 .RE 451 452 .sp 453 .ne 2 454 .na 455 \fB\fB(.,.+1)j\fR\fR 456 .ad 457 .RS 26n 458 The \fBj\fRoin command joins contiguous lines by removing the appropriate 459 new-line characters. If exactly one address is given, this command does 460 nothing. If lines are joined, the current line number is set to the address of 461 the joined line. Otherwise, the current line number is unchanged. 462 .RE 463 464 .sp 465 .ne 2 466 .na 467 \fB\fB(.)k\fR\fIx\fR\fR 468 .ad 469 .RS 26n 470 The mar\fBk\fR command marks the addressed line with name \fIx\fR, which must 471 be an ASCII lower-case letter (\fBa\fR\fB-\fR\fBz\fR). The address \fI a\'x\fR 472 then addresses this line. The current line (\fB\&.\fR) is unchanged. 473 .RE 474 475 .sp 476 .ne 2 477 .na 478 \fB\fB(.,.)l\fR\fR 479 .ad 480 .RS 26n 481 The \fBl\fR command writes to standard output the addressed lines in a visually 482 unambiguous form. The characters ( \fB\e\e\fR, \fB\ea\fR, \fB\eb\fR, \fB\ef\fR, 483 \fB\er\fR, \fB\et\fR, \fB\ev\fR) are written as the corresponding escape 484 sequence. The \fB\en\fR in that table is not applicable. Non-printable 485 characters not in the table are written as one three-digit octal number (with a 486 preceding backslash character) for each byte in the character, with the most 487 significant byte first. 488 .sp 489 Long lines are folded, with the point of folding indicated by writing 490 backslash/newline character. The length at which folding occurs is unspecified, 491 but should be appropriate for the output device. The end of each line is marked 492 with a \fB$\fR. When using the \fB/usr/xpg6/bin/ed\fR command, the end of each 493 line is marked with a \fB$\fR due to folding, and \fB$\fR characters within the 494 text are written with a preceding backslash. An \fBl\fR command can be appended 495 to any other command other than \fBe\fR, \fBE\fR, \fBf\fR, \fBq\fR, \fBQ\fR, 496 \fBr\fR, \fBw\fR, or \fB!\fR. The current line number is set to the address of 497 the last line written. 498 .RE 499 500 .sp 501 .ne 2 502 .na 503 \fB\fB(.,.)m\fR\fIa\fR\fR 504 .ad 505 .RS 26n 506 The \fBm\fRove command repositions the addressed line(s) after the line 507 addressed by \fIa\fR. Address 0 is legal for \fIa\fR and causes the addressed 508 line(s) to be moved to the beginning of the file. It is an error if address 509 \fIa\fR falls within the range of moved lines. The current line (\fB\&.\fR) is 510 left at the last line moved. 511 .RE 512 513 .sp 514 .ne 2 515 .na 516 \fB\fB(.,.)n\fR\fR 517 .ad 518 .RS 26n 519 The \fBn\fRumber command writes the addressed lines, preceding each line by its 520 line number and a tab character. The current line (\fB\&.\fR) is left at the 521 last line written. The \fBn\fR command may be appended to any command other 522 than \fBe\fR, \fBE\fR, \fBf\fR, \fBq\fR, \fBQ\fR, \fBr\fR, \fBw\fR, or \fB!\fR. 523 .RE 524 525 .sp 526 .ne 2 527 .na 528 \fB\fB(.,.)p\fR\fR 529 .ad 530 .RS 26n 531 The \fBp\fRrint command writes the addressed lines to standard output. The 532 current line (\fB\&.\fR) is left at the last line written. The \fBp\fR command 533 may be appended to any command other than \fBe\fR, \fBE\fR, \fBf\fR, \fBq\fR, 534 \fBQ\fR, \fBr\fR, \fBw\fR, or \fB!\fR. For example, \fBdp\fR deletes the 535 current line and writes the new current line. 536 .RE 537 538 .sp 539 .ne 2 540 .na 541 \fB\fBP\fR\fR 542 .ad 543 .RS 26n 544 The \fBP\fR command causes \fBed\fR to prompt with an asterisk (\fB*\fR) (or 545 \fIstring\fR, if \fB-p\fR is specified) for all subsequent commands. The 546 \fBP\fR command alternatively turns this mode on and off; it is initially on if 547 the \fB-p\fR option is specified, otherwise off. The current line is unchanged. 548 .RE 549 550 .sp 551 .ne 2 552 .na 553 \fB\fBq\fR\fR 554 .ad 555 .RS 26n 556 The \fBq\fRuit command causes \fBed\fR to exit. If the buffer has changed since 557 the last time the entire buffer was written, the user is warned. See 558 DIAGNOSTICS. 559 .RE 560 561 .sp 562 .ne 2 563 .na 564 \fB\fBQ\fR\fR 565 .ad 566 .RS 26n 567 The editor exits without checking if changes have been made in the buffer since 568 the last \fBw\fR command. 569 .RE 570 571 .sp 572 .ne 2 573 .na 574 \fB\fB($)r\fR \fIfile\fR\fR 575 .ad 576 .RS 26n 577 The \fBr\fRead command reads the contents of \fIfile\fR into the buffer. If 578 \fIfile\fR is not given, the currently remembered file name, if any, is used 579 (see the \fBe\fR and \fBf\fR commands). The currently remembered file name is 580 \fBnot\fR changed unless \fIfile\fR is the very first file name mentioned since 581 \fBed\fR was invoked. Address 0 is legal for \fBr\fR and causes the file to be 582 read in at the beginning of the buffer. If the read is successful and the 583 \fB-s\fR option was not specified, the number of characters read is written to 584 standard output in the following format: 585 .sp 586 .in +2 587 .nf 588 \fB%d\en\fR, <\fInumber of bytes read\fR> 589 .fi 590 .in -2 591 .sp 592 593 The current line (\fB\&.\fR) is set to the last line read. If \fIfile\fR is 594 replaced by \fB!\fR, the rest of the line is taken to be a shell command (see 595 \fBsh\fR(1)) whose output is to be read. For example, \fB$r !ls\fR appends the 596 current directory to the end of the file being edited. Such a shell command is 597 \fBnot\fR remembered as the current file name. 598 .RE 599 600 .sp 601 .ne 2 602 .na 603 \fB\fB(.,.)s/\fR\fIRE\fR\fB/\fR\fIreplacement\fR\fB/\fR\fR 604 .ad 605 .br 606 .na 607 \fB\fB(.,.)s/\fR\fIRE\fR\fB/\fR\fIreplacement\fR\fB/\fR\fIcount\fR, 608 \fIcount\fR=[\fB1-2047\fR]\fR 609 .ad 610 .br 611 .na 612 \fB\fB(.,.)s/\fR\fIRE\fR\fB/\fR\fIreplacement\fR\fB/g\fR\fR 613 .ad 614 .br 615 .na 616 \fB\fB(.,.)s/\fR\fIRE\fR\fB/\fR\fIreplacement\fR\fB/l\fR\fR 617 .ad 618 .br 619 .na 620 \fB\fB(.,.)s/\fR\fIRE\fR\fB/\fR\fIreplacement\fR\fB/n\fR\fR 621 .ad 622 .br 623 .na 624 \fB\fB(.,.)s/\fR\fIRE\fR\fB/\fR\fIreplacement\fR\fB/p\fR\fR 625 .ad 626 .sp .6 627 .RS 4n 628 The \fBs\fRubstitute command searches each addressed line for an occurrence of 629 the specified \fIRE\fR. Zero or more substitution commands can be specified. In 630 each line in which a match is found, all (non-overlapped) matched strings are 631 replaced by the \fIreplacement\fR if the global replacement indicator \fBg\fR 632 appears after the command. If the global indicator does not appear, only the 633 first occurrence of the matched string is replaced. If a number \fIcount\fR 634 appears after the command, only the \fIcount\fR-th occurrence of the matched 635 string on each addressed line is replaced. It is an error if the substitution 636 fails on \fBall\fR addressed lines. Any character other than space or new-line 637 may be used instead of the slash (\fB/\fR) to delimit the \fIRE\fR and the 638 \fIreplacement\fR. The current line (\fB\&.\fR) is left at the last line on 639 which a substitution occurred. Within the \fIRE\fR, the \fIRE\fR delimiter 640 itself can be used as a literal character if it is preceded by a backslash. See 641 also the last paragraph before FILES below. 642 .sp 643 An ampersand (\fB&\fR) appearing in the \fIreplacement\fR is replaced by the 644 string matching the \fIRE\fR on the current line. The special meaning of 645 \fB&\fR in this context may be suppressed by preceding it by \fB\e\fR\|. As a 646 more general feature, the characters \fB\e\fR\fIn\fR, where \fIn\fR is a digit, 647 are replaced by the text matched by the \fIn\fR-th regular subexpression of the 648 specified \fIRE\fR enclosed between \fB\e(\fR and \fB\e)\fR\&. When nested 649 parenthesized subexpressions are present, \fIn\fR is determined by counting 650 occurrences of \fB\e(\fR starting from the left. When the character \fB%\fR is 651 the only character in the \fIreplacement\fR, the \fIreplacement\fR used in the 652 most recent substitute command is used as the \fIreplacement\fR in the current 653 substitute command. If there was no previous substitute command, the use of 654 \fB%\fR in this manner is an error. The \fB%\fR loses its special meaning when 655 it is in a replacement string of more than one character or is preceded by a 656 \fB\e\fR\|. For each backslash (\e) encountered in scanning \fIreplacement\fR 657 from beginning to end, the following character loses its special meaning (if 658 any). It is unspecified what special meaning is given to any character other 659 than \fB&\fR, \fB\e\fR, \fB%\fR, or digits. 660 .sp 661 A line may be split by substituting a new-line character into it. The new-line 662 in the \fIreplacement\fR must be escaped by preceding it by \fB\e\fR\&. Such 663 substitution cannot be done as part of a \fBg\fR or \fBv\fR command list. The 664 current line number is set to the address of the last line on which a 665 substitution is performed. If no substitution is performed, the current line 666 number is unchanged. If a line is split, a substitution is considered to have 667 been performed on each of the new lines for the purpose of determining the new 668 current line number. A substitution is considered to have been performed even 669 if the replacement string is identical to the string that it replaces. 670 .sp 671 The substitute command supports the following indicators: 672 .sp 673 .ne 2 674 .na 675 \fB\fIcount\fR\fR 676 .ad 677 .RS 9n 678 Substitute for the \fIcount\fRth occurrence only of the \fIRE\fR found on each 679 addressed line. \fIcount\fR must be between \fB1\fR-\fB2047\fR. 680 .RE 681 682 .sp 683 .ne 2 684 .na 685 \fB\fBg\fR\fR 686 .ad 687 .RS 9n 688 Globally substitute for all non-overlapping instances of the \fIRE\fR rather 689 than just the first one. If both \fBg\fR and \fIcount\fR are specified, the 690 results are unspecified. 691 .RE 692 693 .sp 694 .ne 2 695 .na 696 \fB\fBl\fR\fR 697 .ad 698 .RS 9n 699 Write to standard output the final line in which a substitution was made. The 700 line is written in the format specified for the \fBl\fR command. 701 .RE 702 703 .sp 704 .ne 2 705 .na 706 \fB\fBn\fR\fR 707 .ad 708 .RS 9n 709 Write to standard output the final line in which a substitution was made. The 710 line is written in the format specified for the \fBn\fR command. 711 .RE 712 713 .sp 714 .ne 2 715 .na 716 \fB\fBp\fR\fR 717 .ad 718 .RS 9n 719 Write to standard output the final line in which a substitution was made. The 720 line will be written in the format specified for the \fBp\fR command. 721 .RE 722 723 .RE 724 725 .sp 726 .ne 2 727 .na 728 \fB\fB(.,.)t\fR\fIa\fR\fR 729 .ad 730 .sp .6 731 .RS 4n 732 This command acts just like the \fBm\fR command, except that a \fIcopy\fR of 733 the addressed lines is placed after address \fBa\fR (which may be 0). The 734 current line (\fB\&.\fR) is left at the last line copied. 735 .RE 736 737 .sp 738 .ne 2 739 .na 740 \fB\fBu\fR\fR 741 .ad 742 .sp .6 743 .RS 4n 744 The \fBu\fRndo command nullifies the effect of the most recent command that 745 modified anything in the buffer, namely the most recent \fBa\fR, \fBc\fR, 746 \fBd\fR, \fBg\fR, \fBi\fR, \fBj\fR, \fBm\fR, \fBr\fR, \fBs\fR, \fBt\fR, 747 \fBu\fR, \fBv\fR, \fBG\fR, or \fBV\fR command. All changes made to the buffer 748 by a \fBg\fR, \fBG\fR, \fBv\fR, or \fBV\fR global command is undone as a single 749 change.If no changes were made by the global command (such as with \fBg/\fR 750 \fIRE\fR\fB/p\fR), the \fBu\fR command has no effect. The current line number 751 is set to the value it had immediately before the command being undone 752 started. 753 .RE 754 755 .sp 756 .ne 2 757 .na 758 \fB\fB(1,$)v/\fR\fIRE\fR\fB/\fR\fIcommand list\fR\fR 759 .ad 760 .sp .6 761 .RS 4n 762 This command is the same as the global command \fBg\fR, except that the lines 763 marked during the first step are those that do \fBnot\fR match the \fIRE\fR. 764 .RE 765 766 .sp 767 .ne 2 768 .na 769 \fB\fB(1,$)V/\fR\fIRE\fR\fB/\fR\fR 770 .ad 771 .sp .6 772 .RS 4n 773 This command is the same as the interactive global command \fBG\fR, except that 774 the lines that are marked during the first step are those that do \fBnot\fR 775 match the \fIRE\fR. 776 .RE 777 778 .sp 779 .ne 2 780 .na 781 \fB\fB(1,$)w\fR \fIfile\fR\fR 782 .ad 783 .sp .6 784 .RS 4n 785 The \fBw\fRrite command writes the addressed lines into \fIfile\fR. If 786 \fIfile\fR does not exist, it is created with mode \fB666\fR (readable and 787 writable by everyone), unless your file creation mask dictates otherwise. See 788 the description of the \fBumask\fR special command on \fBsh\fR(1). The 789 currently remembered file name is \fBnot\fR changed unless \fIfile\fR is the 790 very first file name mentioned since \fBed\fR was invoked. If no file name is 791 given, the currently remembered file name, if any, is used (see the \fBe\fR and 792 \fBf\fR commands). The current line (\fB\&.\fR) is unchanged. If the command is 793 successful, the number of characters written is printed, unless the \fB-s\fR 794 option is specified in the following format: 795 .sp 796 .in +2 797 .nf 798 \fB"%d\en",\fR<\fInumber of bytes written\fR> 799 .fi 800 .in -2 801 .sp 802 803 If \fIfile\fR is replaced by \fB!\fR, the rest of the line is taken to be a 804 shell (see \fBsh\fR(1)) command whose standard input is the addressed lines. 805 Such a shell command is \fInot\fR remembered as the current path name. This 806 usage of the write command with \fB!\fR is to be considered as a ``last \fBw\fR 807 command that wrote the entire buffer''. 808 .RE 809 810 .sp 811 .ne 2 812 .na 813 \fB\fB(1,$)W\fR \fIfile\fR\fR 814 .ad 815 .RS 19n 816 This command is the same as the \fBw\fRrite command above, except that it 817 appends the addressed lines to the end of \fIfile\fR if it exists. If 818 \fIfile\fR does not exist, it is created as described above for the \fBw\fR 819 command. 820 .RE 821 822 .sp 823 .ne 2 824 .na 825 \fB\fBX\fR\fR 826 .ad 827 .RS 19n 828 An educated guess is made to determine whether text read for the \fBe\fR and 829 \fBr\fR commands is encrypted. A null key turns off encryption. Subsequent 830 \fBe\fR, \fBr\fR, and \fBw\fR commands will use this key to encrypt or decrypt 831 the text. An explicitly empty key turns off encryption. Also, see the \fB-x\fR 832 option of \fBed\fR. 833 .RE 834 835 .sp 836 .ne 2 837 .na 838 \fB\fB($)=\fR\fR 839 .ad 840 .RS 19n 841 The line number of the addressed line is written to standard output in the 842 following format: 843 .sp 844 .in +2 845 .nf 846 \fB"%d\en"\fR<\fIline number\fR> 847 .fi 848 .in -2 849 .sp 850 851 The current line number is unchanged by this command. 852 .RE 853 854 .sp 855 .ne 2 856 .na 857 \fB\fB!\fR\fIshell command\fR\fR 858 .ad 859 .RS 19n 860 The remainder of the line after the \fB!\fR is sent to the UNIX system shell 861 (see \fBsh\fR(1)) to be interpreted as a command. Within the text of that 862 command, the unescaped character \fB%\fR is replaced with the remembered file 863 name. If a \fB!\fR appears as the first character of the shell command, it is 864 replaced with the text of the previous shell command. Thus, \fB!!\fR repeats 865 the last shell command. If any replacements of \fB%\fR or \fB!\fR are 866 performed, the modified line is written to the standard output before 867 \fIcommand\fR is executed. The \fB!\fR command will write: 868 .sp 869 \fB"!\en"\fR 870 .sp 871 to standard output upon completion, unless the \fB-s\fR option is specified. 872 The current line number is unchanged. 873 .RE 874 875 .sp 876 .ne 2 877 .na 878 \fB\fB(.+1)\fR<new-line>\fR 879 .ad 880 .RS 19n 881 An address alone on a line causes the addressed line to be written. A new-line 882 alone is equivalent to \fB\&.+1p\fR. It is useful for stepping forward through 883 the buffer. The current line number will be set to the address of the written 884 line. 885 .RE 886 887 .sp 888 .LP 889 If an interrupt signal (ASCII DEL or BREAK) is sent, \fBed\fR writes a 890 "\fB?\en\fR" and returns to \fBits\fR command level. 891 .sp 892 .LP 893 The \fBed\fR utility takes the standard action for all signals with the 894 following exceptions: 895 .sp 896 .ne 2 897 .na 898 \fB\fBSIGINT\fR\fR 899 .ad 900 .RS 10n 901 The \fBed\fR utility interrupts its current activity, writes the string 902 "\fB?\en\fR" to standard output, and returns to command mode. 903 .RE 904 905 .sp 906 .ne 2 907 .na 908 \fB\fBSIGHUP\fR\fR 909 .ad 910 .RS 10n 911 If the buffer is not empty and has changed since the last write, the \fBed\fR 912 utility attempts to write a copy of the buffer in a file. First, the file named 913 \fBed.hup\fR in the current directory is used. If that fails, the file named 914 \fBed.hup\fR in the directory named by the \fBHOME\fR environment variable is 915 used. In any case, the \fBed\fR utility exits without returning to command 916 mode. 917 .RE 918 919 .sp 920 .LP 921 Some size limitations are in effect: 512 characters in a line, 256 characters 922 in a global command list, and 255 characters in the path name of a file 923 (counting slashes). The limit on the number of lines depends on the amount of 924 user memory. Each line takes 1 word. 925 .sp 926 .LP 927 When reading a file, \fBed\fR discards \fBASCII\fR and \fBNUL\fR characters. 928 .sp 929 .LP 930 If a file is not terminated by a new-line character, \fBed\fR adds one and puts 931 out a message explaining what it did. 932 .sp 933 .LP 934 If the closing delimiter of an \fBRE\fR or of a replacement string (for 935 example, \fB/\fR) would be the last character before a new-line, that delimiter 936 may be omitted, in which case the addressed line is written. The following 937 pairs of commands are equivalent: 938 .sp 939 .ne 2 940 .na 941 \fB\fBs/s1/s2\fR\fR 942 .ad 943 .RS 11n 944 \fBs/s1/s2/p\fR 945 .RE 946 947 .sp 948 .ne 2 949 .na 950 \fB\fBg/s1\fR\fR 951 .ad 952 .RS 11n 953 \fBg/s1/p\fR 954 .RE 955 956 .sp 957 .ne 2 958 .na 959 \fB\fB?s1\fR\fR 960 .ad 961 .RS 11n 962 \fB?s1?\fR 963 .RE 964 965 .sp 966 .LP 967 If an invalid command is entered, \fBed\fR writes the string: 968 .sp 969 .LP 970 \fB"?\en"\fR 971 .sp 972 .LP 973 (followed by an explanatory message if \fIhelp mode\fR has been enabled by the 974 \fBH\fR command) to standard output and continues in command mode with the 975 current line number unchanged. 976 .SH OPTIONS 977 .sp 978 .ne 2 979 .na 980 \fB\fB-C\fR\fR 981 .ad 982 .RS 13n 983 Encryption option. The same as the \fB-x\fR option, except that \fBed\fR 984 simulates a \fBC\fR command. The \fBC\fR command is like the \fBX\fR command, 985 except that all text read in is assumed to have been encrypted. 986 .RE 987 988 .sp 989 .ne 2 990 .na 991 \fB\fB\fR\fB-p\fR\fIstring\fR \fR 992 .ad 993 .RS 13n 994 Allows the user to specify a prompt string. By default, there is no prompt 995 string. 996 .RE 997 998 .sp 999 .ne 2 1000 .na 1001 \fB\fB-s\fR | \fB-;\fR\fR 1002 .ad 1003 .RS 13n 1004 Suppresses the writing of character counts by \fBe\fR, \fBr\fR, and \fBw\fR 1005 commands, of diagnostics from \fBe\fR and \fBq\fR commands, and of the \fB!\fR 1006 prompt after a \fB!\fR\fIshell command\fR. 1007 .RE 1008 1009 .sp 1010 .ne 2 1011 .na 1012 \fB\fB-x\fR\fR 1013 .ad 1014 .RS 13n 1015 Encryption option. When \fB-x\fR is used, \fBed\fR simulates an \fBX\fR command 1016 and prompts the user for a key. The \fBX\fR command makes an educated guess to 1017 determine whether text read in is encrypted or not. The temporary buffer file 1018 is encrypted also, using a transformed version of the key typed in for the 1019 \fB-x\fR option. See NOTES. 1020 .RE 1021 1022 .SH OPERANDS 1023 .sp 1024 .LP 1025 The following operand is supported: 1026 .sp 1027 .ne 2 1028 .na 1029 \fB\fIfile\fR\fR 1030 .ad 1031 .RS 8n 1032 If \fIfile\fR is specified, \fBed\fR simulates an \fBe\fR command on the file 1033 named by the path name \fIfile\fR before accepting commands from the standard 1034 input. 1035 .RE 1036 1037 .SH USAGE 1038 .sp 1039 .LP 1040 See \fBlargefile\fR(5) for the description of the behavior of \fBed\fR and 1041 \fBred\fR when encountering files greater than or equal to 2 Gbyte ( 2^31 1042 bytes). 1043 .SH ENVIRONMENT VARIABLES 1044 .sp 1045 .LP 1046 See \fBenviron\fR(5) for descriptions of the following environment variables 1047 that affect the execution of \fBed\fR: \fBHOME\fR, \fBLANG\fR, \fBLC_ALL\fR, 1048 \fBLC_CTYPE\fR, \fBLC_COLLATE\fR, \fBLC_MESSAGES\fR, and \fBNLSPATH\fR. 1049 .SH EXIT STATUS 1050 .sp 1051 .LP 1052 The following exit values are returned: 1053 .sp 1054 .ne 2 1055 .na 1056 \fB\fB0\fR\fR 1057 .ad 1058 .RS 6n 1059 Successful completion without any file or command errors. 1060 .RE 1061 1062 .sp 1063 .ne 2 1064 .na 1065 \fB\fB>0\fR\fR 1066 .ad 1067 .RS 6n 1068 An error occurred. 1069 .RE 1070 1071 .SH FILES 1072 .sp 1073 .ne 2 1074 .na 1075 \fB\fB$TMPDIR\fR\fR 1076 .ad 1077 .RS 12n 1078 If this environment variable is not \fINULL\fR, its value is used in place of 1079 \fB/var/tmp\fR as the directory name for the temporary work file. 1080 .RE 1081 1082 .sp 1083 .ne 2 1084 .na 1085 \fB\fB/var/tmp\fR\fR 1086 .ad 1087 .RS 12n 1088 If \fB/var/tmp\fR exists, it is used as the directory name for the temporary 1089 work file. 1090 .RE 1091 1092 .sp 1093 .ne 2 1094 .na 1095 \fB\fB/tmp\fR\fR 1096 .ad 1097 .RS 12n 1098 If the environment variable \fBTMPDIR\fR does not exist or is \fINULL,\fR and 1099 if \fB/var/tmp\fR does not exist, then \fB/tmp\fR is used as the directory name 1100 for the temporary work file. 1101 .RE 1102 1103 .sp 1104 .ne 2 1105 .na 1106 \fB\fBed.hup\fR\fR 1107 .ad 1108 .RS 12n 1109 Work is saved here if the terminal is hung up. 1110 .RE 1111 1112 .SH ATTRIBUTES 1113 .sp 1114 .LP 1115 See \fBattributes\fR(5) for descriptions of the following attributes: 1116 .SS "/usr/bin/ed, /usr/bin/red" 1117 .sp 1118 1119 .sp 1120 .TS 1121 box; 1122 c | c 1123 l | l . 1124 ATTRIBUTE TYPE ATTRIBUTE VALUE 1125 _ 1126 CSI Enabled 1127 .TE 1128 1129 .SS "/usr/xpg4/bin/ed" 1130 .sp 1131 1132 .sp 1133 .TS 1134 box; 1135 c | c 1136 l | l . 1137 ATTRIBUTE TYPE ATTRIBUTE VALUE 1138 _ 1139 CSI Enabled 1140 _ 1141 Interface Stability Standard 1142 .TE 1143 1144 .SS "/usr/xpg6/bin/ed" 1145 .sp 1146 1147 .sp 1148 .TS 1149 box; 1150 c | c 1151 l | l . 1152 ATTRIBUTE TYPE ATTRIBUTE VALUE 1153 _ 1154 CSI Enabled 1155 _ 1156 Interface Stability Standard 1157 .TE 1158 1159 .SH SEE ALSO 1160 .sp 1161 .LP 1162 \fBedit\fR(1), \fBex\fR(1), \fBgrep\fR(1), \fBksh\fR(1), 1163 \fBsed\fR(1), \fBsh\fR(1), \fBstty\fR(1), \fBumask\fR(1), \fBvi\fR(1), 1164 \fBfspec\fR(4), \fBattributes\fR(5), \fBenviron\fR(5), \fBlargefile\fR(5), 1165 \fBregex\fR(5), \fBstandards\fR(5) 1166 .SH DIAGNOSTICS 1167 .sp 1168 .ne 2 1169 .na 1170 \fB\fB?\fR\fR 1171 .ad 1172 .RS 9n 1173 for command errors. 1174 .RE 1175 1176 .sp 1177 .ne 2 1178 .na 1179 \fB\fB?\fR\fIfile\fR\fR 1180 .ad 1181 .RS 9n 1182 for an inaccessible file. Use the \fBh\fRelp and \fBH\fRelp commands for 1183 detailed explanations. 1184 .RE 1185 1186 .sp 1187 .LP 1188 If changes have been made in the buffer since the last \fBw\fR command that 1189 wrote the entire buffer, \fBed\fR warns the user if an attempt is made to 1190 destroy \fBed\fR's buffer via the \fBe\fR or \fBq\fR commands. It writes 1191 \fB?\fR and allows one to continue editing. A second \fBe\fR or \fBq\fR command 1192 at this point will take effect. The \fB-s\fR command-line option inhibits this 1193 feature. 1194 .SH NOTES 1195 .sp 1196 .LP 1197 The \fB-\fR option, although it continues to be supported, has been replaced in 1198 the documentation by the \fB-s\fR option that follows the \fBCommand Syntax 1199 Standard\fR (see \fBIntro\fR(1)). 1200 .sp 1201 .LP 1202 A \fB!\fR command cannot be subject to a \fBg\fR or a \fBv\fR command. 1203 .sp 1204 .LP 1205 The \fB!\fR command and the \fB!\fR escape from the \fBe\fR, \fBr\fR, and 1206 \fBw\fR commands cannot be used if the editor is invoked from a restricted 1207 shell (see \fBsh\fR(1)). 1208 .sp 1209 .LP 1210 The sequence \fB\en\fR in an \fBRE\fR does not match a new-line character. 1211 .sp 1212 .LP 1213 If the editor input is coming from a command file (for example, \fBed\fR 1214 \fIfile\fR \fB<\fR \fIed_cmd_file\fR), the editor exits at the first failure. 1215 .sp 1216 .LP 1217 Loading an alternate \fBmalloc()\fR library using the environment variable 1218 \fBLD_PRELOAD\fR can cause problems for \fB/usr/bin/ed\fR.