POSIX revision 1.8
11.7SalmThis version of ed(1) is not strictly POSIX compliant, as described in 21.7Salmthe POSIX 1003.2 document. The following is a summary of the omissions, 31.7Salmextensions and possible deviations from POSIX 1003.2. 41.7Salm 51.7SalmOMISSIONS 61.7Salm--------- 71.7Salm1) Locale(3) is not supported yet. 81.7Salm 91.7Salm2) For backwards compatibility, the POSIX rule that says a range of 101.7Salm addresses cannot be used where only a single address is expected has 111.7Salm been relaxed. 121.7Salm 131.8Salm3) To support the BSD `s' command (see extension [1] below), 141.8Salm substitution patterns cannot be delimited by numbers or the characters 151.8Salm `r', `g' and `p'. In contrast, POSIX specifies any character expect 161.8Salm space or newline can used as a delimiter. 171.8Salm 181.7SalmEXTENSIONS 191.7Salm---------- 201.7Salm1) BSD commands have been implemented wherever they do not conflict with 211.7Salm the POSIX standard. The BSD-ism's included are: 221.8Salm i) `s' (i.e., s[n][rgp]*) to repeat a previous substitution, 231.7Salm ii) `W' for appending text to an existing file, 241.7Salm iii) `wq' for exiting after a write, 251.7Salm iv) `z' for scrolling through the buffer, and 261.7Salm v) BSD line addressing syntax (i.e., `^' and `%') is recognized. 271.7Salm 281.7Salm2) If crypt(3) is available, files can be read and written using DES 291.7Salm encryption. The `x' command prompts the user to enter a key used for 301.7Salm encrypting/ decrypting subsequent reads and writes. If only a newline 311.7Salm is entered as the key, then encryption is disabled. Otherwise, a key 321.7Salm is read in the same manner as a password entry. The key remains in 331.7Salm effect until encryption is disabled. For more information on the 341.7Salm encryption algorithm, see the bdes(1) man page. Encryption/decryption 351.8Salm should be fully compatible with SunOS des(1). 361.7Salm 371.7Salm3) The POSIX interactive global commands `G' and `V' are extended to 381.7Salm support multiple commands, including `a', `i' and `c'. The command 391.7Salm format is the same as for the global commands `g' and `v', i.e., one 401.7Salm command per line with each line, except for the last, ending in a 411.7Salm backslash (\). 421.7Salm 431.8Salm4) An extension to the POSIX file commands `E', `e', `r', `W' and `w' is 441.7Salm that <file> arguments are processed for backslash escapes, i.e., any 451.7Salm character preceded by a backslash is interpreted literally. If the 461.7Salm first unescaped character of a <file> argument is a bang (!), then the 471.7Salm rest of the line is interpreted as a shell command, and no escape 481.7Salm processing is performed by ed. 491.7Salm 501.8Salm5) For SunOS ed(1) compatibility, ed runs in restricted mode if invoked 511.7Salm as red. This limits editing of files in the local directory only and 521.7Salm prohibits shell commands. 531.7Salm 541.7SalmDEVIATIONS 551.7Salm---------- 561.8Salm1) Though ed is not a stream editor, it can be used to edit binary files. 571.8Salm To assist in binary editing, when a file containing at least one ASCII 581.8Salm NUL character is written, a newline is not appended if it did not 591.8Salm already contain one upon reading. In particular, reading /dev/null 601.8Salm prior to writing prevents appending a newline to a binary file. 611.8Salm 621.8Salm For example, to create a file with ed containing a single NUL character: 631.8Salm $ ed file 641.8Salm a 651.8Salm ^@ 661.8Salm . 671.8Salm r /dev/null 681.8Salm wq 691.8Salm 701.8Salm Similarly, to remove a newline from the end of binary `file': 711.8Salm $ ed file 721.8Salm r /dev/null 731.8Salm wq 741.8Salm 751.8Salm2) Since the behavior of `u' (undo) within a `g' (global) command list is 761.8Salm not specified by POSIX, it follows the behavior of the SunOS ed: 771.8Salm undo forces a global command list to be executed only once, rather than 781.8Salm for each line matching a global pattern. In addtion, each instance of 791.8Salm `u' within a global command undoes all previous commands (including 801.8Salm undo's) in the command list. This seems the best way, since the 811.8Salm alternatives are either too complicated to implement or too confusing 821.8Salm to use. 831.8Salm 841.8Salm The global/undo combination is useful for masking errors that 851.8Salm would otherwise cause a script to fail. For instance, an ed script 861.8Salm to remove any occurences of either `censor1' or `censor2' might be 871.8Salm written as: 881.8Salm ed - file <<EOF 891.8Salm 1g/.*/u\ 901.8Salm ,s/censor1//g\ 911.8Salm ,s/censor2//g 921.8Salm ... 931.7Salm 941.8Salm3) The `m' (move) command within a `g' command list also follows the SunOS 951.7Salm ed implementation: any moved lines are removed from the global command's 961.7Salm `active' list. 971.7Salm 981.8Salm4) If ed is invoked with a name argument prefixed by a bang (!), then the 991.7Salm remainder of the argument is interpreted as a shell command. To invoke 1001.7Salm ed on a file whose name starts with bang, prefix the name with a 1011.7Salm backslash. 102