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