1.\" $NetBSD: ed.1,v 1.28 2003/09/08 13:13:08 wiz Exp $ 2.\" $OpenBSD: ed.1,v 1.42 2003/07/27 13:25:43 jmc Exp $ 3.\" 4.\" Copyright (c) 1993 Andrew Moore, Talke Studio. 5.\" All rights reserved. 6.\" 7.\" Redistribution and use in source and binary forms, with or without 8.\" modification, are permitted provided that the following conditions 9.\" are met: 10.\" 1. Redistributions of source code must retain the above copyright 11.\" notice, this list of conditions and the following disclaimer. 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in the 14.\" documentation and/or other materials provided with the distribution. 15.\" 16.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26.\" SUCH DAMAGE. 27.\" 28.Dd January 23, 2002 29.Dt ED 1 30.Os 31.Sh NAME 32.Nm ed 33.Nd text editor 34.Sh SYNOPSIS 35.Nm 36.Op Fl 37.Op Fl Esx 38.Op Fl p Ar string 39.Op Ar file 40.Sh DESCRIPTION 41.Nm 42is a line-oriented text editor. 43It is used to create, display, modify, and otherwise manipulate text files. 44If invoked with a 45.Ar file 46argument, then a copy of 47.Ar file 48is read into the editor's buffer. 49Changes are made to this copy and not directly to 50.Ar file 51itself. 52Upon quitting 53.Nm , 54any changes not explicitly saved with a 55.Ic w 56command are lost. 57.Pp 58Editing is done in two distinct modes: 59.Em command 60and 61.Em input . 62When first invoked, 63.Nm 64is in command mode. 65In this mode, commands are read from the standard input and 66executed to manipulate the contents of the editor buffer. 67.Pp 68A typical command might look like: 69.Bd -literal -offset indent 70,s/old/new/g 71.Ed 72.Pp 73which replaces all occurrences of the string 74.Pa old 75with 76.Pa new . 77.Pp 78When an input command, such as 79.Ic a 80(append), 81.Ic i 82(insert), 83or 84.Ic c 85(change) is given, 86.Nm 87enters input mode. 88This is the primary means of adding text to a file. 89In this mode, no commands are available; 90instead, the standard input is written directly to the editor buffer. 91Lines consist of text up to and including a newline character. 92Input mode is terminated by entering a single period 93.Pq Ql \&. 94on a line. 95.Pp 96All 97.Nm 98commands operate on whole lines or ranges of lines; e.g., 99the 100.Ic d 101command deletes lines; the 102.Ic m 103command moves lines, and so on. 104It is possible to modify only a portion of a line by means of replacement, 105as in the example above. 106However, even here, the 107.Ic s 108command is applied to whole lines at a time. 109.Pp 110In general, 111.Nm 112commands consist of zero or more line addresses, followed by a single 113character command and possibly additional parameters; i.e., 114commands have the structure: 115.Bd -literal -offset indent 116[address [,address]]command[parameters] 117.Ed 118.Pp 119The address(es) indicate the line or range of lines to be affected by the 120command. 121If fewer addresses are given than the command accepts, then 122default addresses are supplied. 123.Pp 124The options are as follows: 125.Bl -tag -width Ds 126.It Fl 127Same as the 128.Fl s 129option (deprecated). 130.It Fl E 131Enables the use of extended regular expressions instead of the basic 132regular expressions that are normally used. 133.It Fl p Ar string 134Specifies a command prompt. 135This may be toggled on and off with the 136.Ic P 137command. 138.It Fl s 139Suppress diagnostics. 140This should be used if 141.Nm 142standard input is from a script. 143.It Fl x 144Prompt for an encryption key to be used in subsequent reads and writes 145(see the 146.Ic x 147command). 148.It Ar file 149Specifies the name of a file to read. 150If 151.Ar file 152is prefixed with a 153bang 154.Pq Ql \&! , 155then it is interpreted as a shell command. 156In this case, what is read is the standard output of 157.Ar file 158executed via 159.Xr sh 1 . 160To read a file whose name begins with a bang, prefix the 161name with a backslash 162.Pq Ql \e . 163The default filename is set to 164.Ar file 165only if it is not prefixed with a bang. 166.El 167.Ss LINE ADDRESSING 168An address represents the number of a line in the buffer. 169.Nm 170maintains a 171.Em current address 172which is typically supplied to commands as the default address 173when none is specified. 174When a file is first read, the current address is set to the last line 175of the file. 176In general, the current address is set to the last line affected by a command. 177.Pp 178A line address is 179constructed from one of the bases in the list below, optionally followed 180by a numeric offset. 181The offset may include any combination of digits, operators (i.e., 182.Sq + , 183.Sq - , 184and 185.Sq ^ ) , 186and whitespace. 187Addresses are read from left to right, and their values are computed 188relative to the current address. 189.Pp 190One exception to the rule that addresses represent line numbers is the 191address 192.Em 0 193(zero). 194This means 195.Dq before the first line , 196and is legal wherever it makes sense. 197.Pp 198An address range is two addresses separated either by a comma or semi-colon. 199The value of the first address in a range cannot exceed the 200value of the second. 201If only one address is given in a range, 202then the second address is set to the given address. 203If an 204.Em n Ns No -tuple 205of addresses is given where 206.Em n \*[Gt] 2 , 207then the corresponding range is determined by the last two addresses in the 208.Em n Ns No -tuple. 209If only one address is expected, then the last address is used. 210.Pp 211Each address in a comma-delimited range is interpreted relative to the 212current address. 213In a semi-colon-delimited range, the first address is 214used to set the current address, and the second address is interpreted 215relative to the first. 216.Pp 217The following address symbols are recognized: 218.Bl -tag -width Ds 219.It Em \&. 220The current line (address) in the buffer. 221.It Em $ 222The last line in the buffer. 223.It Em n 224The 225.Em n Ns No th 226line in the buffer where 227.Em n 228is a number in the range 229.Em [0,$] . 230.It Em - No or Em ^ 231The previous line. 232This is equivalent to 233.Em -1 234and may be repeated with cumulative effect. 235.It Em -n No or Em ^n 236The 237.Em n Ns No th 238previous line, where 239.Em n 240is a non-negative number. 241.It Em + 242The next line. 243This is equivalent to 244.Em +1 245and may be repeated with cumulative effect. 246.It Em +n 247The 248.Em n Ns No th 249next line, where 250.Em n 251is a non-negative number. 252.It Em whitespace Em n 253.Em whitespace 254followed by a number 255.Em n 256is interpreted as 257.Sq Em +n . 258.It Em \&, No or Em % 259The first through last lines in the buffer. 260This is equivalent to the address range 261.Em 1,$ . 262.It Em \&; 263The current through last lines in the buffer. 264This is equivalent to the address range 265.Em .,$ . 266.It Em / Ns Ar re Ns Em / 267The next line containing the regular expression 268.Ar re . 269The search wraps to the beginning of the buffer and continues down to the 270current line, if necessary. 271.Em // 272repeats the last search. 273.It Em ? Ns Ar re Ns Em ? 274The previous line containing the regular expression 275.Ar re . 276The search wraps to the end of the buffer and continues up to the 277current line, if necessary. 278.Em ?? 279repeats the last search. 280.It Em \&\' Ns Ar lc 281The line previously marked by a 282.Ic k 283(mark) command, where 284.Ar lc 285is a lower case letter. 286.El 287.Ss REGULAR EXPRESSIONS 288Regular expressions are patterns used in selecting text. 289For example, the 290.Nm 291command 292.Bd -literal -offset indent 293g/string/ 294.Ed 295.Pp 296prints all lines containing 297.Em string . 298Regular expressions are also used by the 299.Ic s 300command for selecting old text to be replaced with new. 301.Pp 302In addition to specifying string literals, regular expressions can 303represent classes of strings. 304Strings thus represented are said to be matched by the 305corresponding regular expression. 306If it is possible for a regular expression to match several strings in 307a line, then the leftmost longest match is the one selected. 308.Pp 309The following symbols are used in constructing regular expressions: 310.Bl -tag -width Dsasdfsd 311.It Em c 312Any character 313.Em c 314not listed below, including 315.Sq { , 316.Sq } , 317.Sq \&( , 318.Sq \&) , 319.Sq \*[Lt] , 320and 321.Sq \*[Gt] 322matches itself. 323.It Em \ec 324Any backslash-escaped character 325.Em c , 326except for 327.Sq { , 328.Sq } , 329.Sq \&( , 330.Sq \&) , 331.Sq \*[Lt] , 332and 333.Sq \*[Gt] 334matches itself. 335.It Em \&. 336Matches any single character. 337.It Em [char-class] 338Matches any single character in the character class 339.Em char-class . 340See 341.Sx CHARACTER CLASSES 342below for further information. 343.It Em [^char-class] 344Matches any single character, other than newline, not in the 345character class 346.Em char-class . 347.It Em ^ 348If 349.Em ^ 350is the first character of a regular expression, then it 351anchors the regular expression to the beginning of a line. 352Otherwise, it matches itself. 353.It Em $ 354If 355.Em $ 356is the last character of a regular expression, 357it anchors the regular expression to the end of a line. 358Otherwise, it matches itself. 359.It Em \e\*[Lt] 360Anchors the single character regular expression or subexpression 361immediately following it to the beginning of a word. 362(This may not be available.) 363.It Em \e\*[Gt] 364Anchors the single character regular expression or subexpression 365immediately following it to the end of a word. 366(This may not be available.) 367.It Em \e( Ns Ar re Ns Em \e) 368Defines a subexpression 369.Ar re . 370Subexpressions may be nested. 371A subsequent backreference of the form 372.Em \en , 373where 374.Em n 375is a number in the range [1,9], expands to the text matched by the 376.Em n Ns No th 377subexpression. 378For example, the regular expression 379.Em \e(.*\e)\e1 380matches any string consisting of identical adjacent substrings. 381Subexpressions are ordered relative to their left delimiter. 382.It Em * 383Matches the single character regular expression or subexpression 384immediately preceding it zero or more times. 385If 386.Em * 387is the first character of a regular expression or subexpression, 388then it matches itself. 389The 390.Em * 391operator sometimes yields unexpected results. 392For example, the regular expression 393.Em b* 394matches the beginning of the string 395.Em abbb 396(as opposed to the substring 397.Em bbb ) , 398since a null match is the only leftmost match. 399.Sm off 400.It Xo Em \e{ No n,m 401.Em \e}\ \e{ No n, Em \e}\ \& 402.Em \e{ No n Em \e} 403.Xc 404.Sm on 405Matches the single character regular expression or subexpression 406immediately preceding it at least 407.Em n 408and at most 409.Em m 410times. 411If 412.Em m 413is omitted, then it matches at least 414.Em n 415times. 416If the comma is also omitted, then it matches exactly 417.Em n 418times. 419.El 420.Pp 421Additional regular expression operators may be defined depending on the 422particular 423.Xr regex 3 424implementation. 425.Ss CHARACTER CLASSES 426A character class specifies a set of characters. It is written within 427square brackets 428.Pq [] 429and in its most basic form contains just the characters in the set. 430.Pp 431To include a 432.Sq \&] 433in a character class, it must be the first character. 434A range of characters may be specified by separating the end characters 435of the range with a 436.Sq \&- , 437e.g., 438.Sq a-z 439specifies the lower case characters. 440.Pp 441The following literals can also be used within character classes as 442shorthand for particular sets of characters: 443.Bl -tag -offset indent -compact -width [:blahblah:] 444.It [:alnum:] 445Alphanumeric characters. 446.It [:cntrl:] 447Control characters. 448.It [:lower:] 449Lowercase alphabetic characters. 450.It [:space:] 451Whitespace (space, tab, newline, form feed, etc.) 452.It [:alpha:] 453Alphabetic characters. 454.It [:digit:] 455Numeric characters (digits). 456.It [:print:] 457Printable characters. 458.It [:upper:] 459Uppercase alphabetic characters. 460.It [:blank:] 461Blank characters (space and tab). 462.It [:graph:] 463Graphical characters (printing nonblank characters). 464.It [:punct:] 465Punctuation characters. 466.It [:xdigit:] 467Hexadecimal digits. 468.El 469If 470.Sq \&- 471appears as the first or last character of a character class, then 472it matches itself. 473All other characters in a character class match themselves. 474.Pp 475Patterns in 476a character class 477of the form 478.Em [.col-elm.] 479or 480.Em [=col-elm=] 481where 482.Em col-elm 483is a 484.Em collating element 485are interpreted according to 486.Xr locale 5 487(not currently supported). 488See 489.Xr regex 3 490for an explanation of these constructs. 491.Ss COMMANDS 492All 493.Nm 494commands are single characters, though some require additional parameters. 495If a command's parameters extend over several lines, then 496each line except for the last must be terminated with a backslash 497.Pq Ql \e . 498.Pp 499In general, at most one command is allowed per line. 500However, most commands accept a print suffix, which is any of 501.Ic p 502(print), 503.Ic l 504(list), 505or 506.Ic n 507(enumerate), to print the last line affected by the command. 508.Pp 509An interrupt (typically ^C) has the effect of aborting the current command 510and returning the editor to command mode. 511.Pp 512.Nm 513recognizes the following commands. 514The commands are shown together with 515the default address or address range supplied if none is 516specified (in parentheses), and other possible arguments on the right. 517.Bl -tag -width Dxxs 518.It (.) Ns Ic a 519Appends text to the buffer after the addressed line. 520Text is entered in input mode. 521The current address is set to last line entered. 522.It (.,.) Ns Ic c 523Changes lines in the buffer. 524The addressed lines are deleted from the buffer, 525and text is appended in their place. 526Text is entered in input mode. 527The current address is set to last line entered. 528.It (.,.) Ns Ic d 529Deletes the addressed lines from the buffer. 530If there is a line after the deleted range, then the current address is set 531to this line. 532Otherwise the current address is set to the line before the deleted range. 533.It Ic e Ar file 534Edits 535.Ar file , 536and sets the default filename. 537If 538.Ar file 539is not specified, then the default filename is used. 540Any lines in the buffer are deleted before the new file is read. 541The current address is set to the last line read. 542.It Ic e Ar !command 543Edits the standard output of 544.Ar command , 545(see 546.Ic ! Ar command 547below). 548The default filename is unchanged. 549Any lines in the buffer are deleted before the output of 550.Em command 551is read. 552The current address is set to the last line read. 553.It Ic E Ar file 554Edits 555.Ar file 556unconditionally. 557This is similar to the 558.Ic e 559command, except that unwritten changes are discarded without warning. 560The current address is set to the last line read. 561.It Ic f Ar file 562Sets the default filename to 563.Ar file . 564If 565.Ar file 566is not specified, then the default unescaped filename is printed. 567.It (1,$) Ns Ic g Ns Ar /re/command-list 568Applies 569.Ar command-list 570to each of the addressed lines matching a regular expression 571.Ar re . 572The current address is set to the line currently matched before 573.Ar command-list 574is executed. 575At the end of the 576.Ic g 577command, the current address is set to the last line affected by 578.Ar command-list . 579.Pp 580Each command in 581.Ar command-list 582must be on a separate line, 583and every line except for the last must be terminated by a backslash 584.Pq Sq \e . 585Any commands are allowed, except for 586.Ic g , 587.Ic G , 588.Ic v , 589and 590.Ic V . 591A newline alone in 592.Ar command-list 593is equivalent to a 594.Ic p 595command. 596.It (1,$) Ns Ic G Ns Ar /re/ 597Interactively edits the addressed lines matching a regular expression 598.Ar re . 599For each matching line, the line is printed, the current address is set, 600and the user is prompted to enter a 601.Ar command-list . 602At the end of the 603.Ic G 604command, the current address is set to the last line affected by (the last) 605.Ar command-list . 606.Pp 607The format of 608.Ar command-list 609is the same as that of the 610.Ic g 611command. 612A newline alone acts as a null command list. 613A single 614.Sq \*[Am] 615repeats the last non-null command list. 616.It Ic H 617Toggles the printing of error explanations. 618By default, explanations are not printed. 619It is recommended that 620.Nm 621scripts begin with this command to aid in debugging. 622.It Ic h 623Prints an explanation of the last error. 624.It (.) Ns Ic i 625Inserts text in the buffer before the current line. 626Text is entered in input mode. 627The current address is set to the last line entered. 628.It (.,.+1) Ns Ic j 629Joins the addressed lines. 630The addressed lines are deleted from the buffer and replaced by a single 631line containing their joined text. 632The current address is set to the resultant line. 633.It (.) Ns Ic k Ns Ar lc 634Marks a line with a lower case letter 635.Ar lc . 636The line can then be addressed as 637.Ar \&'lc 638(i.e., a single quote followed by 639.Ar lc ) 640in subsequent commands. 641The mark is not cleared until the line is deleted or otherwise modified. 642.It (.,.) Ns Ic l 643Prints the addressed lines unambiguously. 644If a single line fills more than one screen (as might be the case 645when viewing a binary file, for instance), a 646.Dq --More-- 647prompt is printed on the last line. 648.Nm 649waits until the RETURN key is pressed before displaying the next screen. 650The current address is set to the last line printed. 651.It (.,.) Ns Ic m Ns No (.) 652Moves lines in the buffer. 653The addressed lines are moved to after the 654right-hand destination address, which may be the address 655.Em 0 656(zero). 657The current address is set to the last line moved. 658.It (.,.) Ns Ic n 659Prints the addressed lines along with their line numbers. 660The current address is set to the last line printed. 661.It (.,.) Ns Ic p 662Prints the addressed lines. 663The current address is set to the last line printed. 664.It Ic P 665Toggles the command prompt on and off. 666Unless a prompt was specified with the command-line option 667.Fl p Ar string , 668the command prompt is by default turned off. 669.It Ic q 670Quits 671.Nm . 672.It Ic Q 673Quits 674.Nm 675unconditionally. 676This is similar to the 677.Ic q 678command, except that unwritten changes are discarded without warning. 679.It ($) Ns Ic r Ar file 680Reads 681.Ar file 682to after the addressed line. 683If 684.Ar file 685is not specified, then the default filename is used. 686If there was no default filename prior to the command, 687then the default filename is set to 688.Ar file . 689Otherwise, the default filename is unchanged. 690The current address is set to the last line read. 691.It ($) Ns Ic r Ar !command 692Reads to after the addressed line the standard output of 693.Ar command , 694(see the 695.Ic ! 696command below). 697The default filename is unchanged. 698The current address is set to the last line read. 699.Sm off 700.It Xo (.,.) Ic s Ar /re/replacement/ , \ (.,.) 701.Ic s Ar /re/replacement/ Em g , Ar \ (.,.) 702.Ic s Ar /re/replacement/ Em n 703.Xc 704.Sm on 705Replaces text in the addressed lines matching a regular expression 706.Ar re 707with 708.Ar replacement . 709By default, only the first match in each line is replaced. 710If the 711.Em g 712(global) suffix is given, then every match to be replaced. 713The 714.Em n 715suffix, where 716.Em n 717is a positive number, causes only the 718.Em n Ns No th 719match to be replaced. 720It is an error if no substitutions are performed on any of the addressed 721lines. 722The current address is set the last line affected. 723.Pp 724.Ar re 725and 726.Ar replacement 727may be delimited by any character other than space and newline 728(see the 729.Ic s 730command below). 731If one or two of the last delimiters is omitted, then the last line 732affected is printed as though the print suffix 733.Em p 734were specified. 735.Pp 736An unescaped 737.Ql \*[Am] 738in 739.Ar replacement 740is replaced by the currently matched text. 741The character sequence 742.Em \em , 743where 744.Em m 745is a number in the range [1,9], is replaced by the 746.Em m Ns No th 747backreference expression of the matched text. 748If 749.Ar replacement 750consists of a single 751.Ql % , 752then 753.Ar replacement 754from the last substitution is used. 755Newlines may be embedded in 756.Ar replacement 757if they are escaped with a backslash 758.Pq Ql \e . 759.It (.,.) Ns Ic s 760Repeats the last substitution. 761This form of the 762.Ic s 763command accepts a count suffix 764.Em n , 765or any combination of the characters 766.Em r , 767.Em g , 768and 769.Em p . 770If a count suffix 771.Em n 772is given, then only the 773.Em n Ns No th 774match is replaced. 775The 776.Em r 777suffix causes 778the regular expression of the last search to be used instead of 779that of the last substitution. 780The 781.Em g 782suffix toggles the global suffix of the last substitution. 783The 784.Em p 785suffix toggles the print suffix of the last substitution. 786The current address is set to the last line affected. 787.It (.,.) Ns Ic t Ns No (.) 788Copies (i.e., transfers) the addressed lines to after the right-hand 789destination address, which may be the address 790.Em 0 791(zero). 792The current address is set to the last line copied. 793.It Ic u 794Undoes the last command and restores the current address 795to what it was before the command. 796The global commands 797.Ic g , 798.Ic G , 799.Ic v , 800and 801.Ic V 802are treated as a single command by undo. 803.Ic u 804is its own inverse. 805.It (1,$) Ns Ic v Ns Ar /re/command-list 806Applies 807.Ar command-list 808to each of the addressed lines not matching a regular expression 809.Ar re . 810This is similar to the 811.Ic g 812command. 813.It (1,$) Ns Ic V Ns Ar /re/ 814Interactively edits the addressed lines not matching a regular expression 815.Ar re . 816This is similar to the 817.Ic G 818command. 819.It (1,$) Ns Ic w Ar file 820Writes the addressed lines to 821.Ar file . 822Any previous contents of 823.Ar file 824are lost without warning. 825If there is no default filename, then the default filename is set to 826.Ar file , 827otherwise it is unchanged. 828If no filename is specified, then the default filename is used. 829The current address is unchanged. 830.It (1,$) Ns Ic wq Ar file 831Writes the addressed lines to 832.Ar file , 833and then executes a 834.Ic q 835command. 836.It (1,$) Ns Ic w Ar !command 837Writes the addressed lines to the standard input of 838.Ar command , 839(see the 840.Ic ! 841command below). 842The default filename and current address are unchanged. 843.It (1,$) Ns Ic W Ar file 844Appends the addressed lines to the end of 845.Ar file . 846This is similar to the 847.Ic w 848command, except that the previous contents of file are not clobbered. 849The current address is unchanged. 850.It Ic x 851Prompts for an encryption key which is used in subsequent reads and writes. 852If a newline alone is entered as the key, then encryption is turned off. 853Otherwise, echoing is disabled while a key is read. 854Encryption/decryption is done using the 855.Xr bdes 1 856algorithm. 857.It (.+1) Ns Ic z Ns Ar n 858Scrolls 859.Ar n 860lines at a time starting at addressed line. 861If 862.Ar n 863is not specified, then the current window size is used. 864The current address is set to the last line printed. 865.It ($) Ns Ic = 866Prints the line number of the addressed line. 867.It (.+1) Ns Ic newline 868Prints the addressed line, and sets the current address to that line. 869.It Ic ! Ns Ar command 870Executes 871.Ar command 872via 873.Xr sh 1 . 874If the first character of 875.Ar command 876is 877.Ic ! , 878then it is replaced by text of the previous 879.Ic !command . 880.Nm 881does not process 882.Ar command 883for 884.Sq \e 885(backslash) escapes. 886However, an unescaped 887.Sq % 888is replaced by the default filename. 889When the shell returns from execution, a 890.Sq ! 891is printed to the standard output. 892The current line is unchanged. 893.El 894.Sh LIMITATIONS 895.Nm 896processes 897.Em file 898arguments for backslash escapes, i.e., in a filename, 899any characters preceded by a backslash 900.Pq Ql \e 901are interpreted literally. 902.Pp 903If a text (non-binary) file is not terminated by a newline character, 904then 905.Nm 906appends one on reading/writing it. 907In the case of a binary file, 908.Nm 909does not append a newline on reading/writing. 910.Sh ENVIRONMENT 911.Bl -tag -width iTMPDIR 912.It Ev TMPDIR 913The location used to store temporary files. 914.El 915.Sh FILES 916.Bl -tag -width /tmp/ed.* -compact 917.It Pa /tmp/ed.* 918buffer file 919.It Pa ed.hup 920where 921.Nm 922attempts to write the buffer if the terminal hangs up 923.El 924.Sh DIAGNOSTICS 925When an error occurs, 926.Nm 927prints a 928.Dq ? 929and either returns to command mode or exits if its input is from a script. 930An explanation of the last error can be printed with the 931.Ic h 932(help) command. 933.Pp 934Since the 935.Ic g 936(global) command masks any errors from failed searches and substitutions, 937it can be used to perform conditional operations in scripts; e.g., 938.Bd -literal -offset indent 939g/old/s//new/ 940.Ed 941.Pp 942replaces any occurrences of 943.Em old 944with 945.Em new . 946.Pp 947If the 948.Ic u 949(undo) command occurs in a global command list, then 950the command list is executed only once. 951.Pp 952If diagnostics are not disabled, attempting to quit 953.Nm 954or edit another file before writing a modified buffer results in an error. 955If the command is entered a second time, it succeeds, 956but any changes to the buffer are lost. 957.Sh SEE ALSO 958.Xr bdes 1 , 959.Xr sed 1 , 960.Xr sh 1 , 961.Xr vi 1 , 962.Xr regex 3 963.Pp 964USD:09-10 965.Rs 966.%A B. W. Kernighan 967.%A P. J. Plauger 968.%B Software Tools in Pascal 969.%I Addison-Wesley 970.%D 1981 971.Re 972.Sh HISTORY 973An 974.Nm 975command appeared in 976.At v1 . 977