POSIX revision 50471
150471Speter$FreeBSD: head/bin/ed/POSIX 50471 1999-08-27 23:15:48Z peter $ 23044Sdg 31057SalmThis version of ed(1) is not strictly POSIX compliant, as described in 41057Salmthe POSIX 1003.2 document. The following is a summary of the omissions, 51057Salmextensions and possible deviations from POSIX 1003.2. 616Salm 71057SalmOMISSIONS 81057Salm--------- 91057Salm1) Locale(3) is not supported yet. 1016Salm 111057Salm2) For backwards compatibility, the POSIX rule that says a range of 121057Salm addresses cannot be used where only a single address is expected has 131057Salm been relaxed. 1416Salm 151057Salm3) To support the BSD `s' command (see extension [1] below), 161057Salm substitution patterns cannot be delimited by numbers or the characters 171057Salm `r', `g' and `p'. In contrast, POSIX specifies any character expect 181057Salm space or newline can used as a delimiter. 1916Salm 201057SalmEXTENSIONS 211057Salm---------- 221057Salm1) BSD commands have been implemented wherever they do not conflict with 231057Salm the POSIX standard. The BSD-ism's included are: 241057Salm i) `s' (i.e., s[n][rgp]*) to repeat a previous substitution, 251057Salm ii) `W' for appending text to an existing file, 261057Salm iii) `wq' for exiting after a write, 271057Salm iv) `z' for scrolling through the buffer, and 281057Salm v) BSD line addressing syntax (i.e., `^' and `%') is recognized. 2916Salm 301057Salm2) If crypt(3) is available, files can be read and written using DES 311057Salm encryption. The `x' command prompts the user to enter a key used for 321057Salm encrypting/ decrypting subsequent reads and writes. If only a newline 331057Salm is entered as the key, then encryption is disabled. Otherwise, a key 341057Salm is read in the same manner as a password entry. The key remains in 351057Salm effect until encryption is disabled. For more information on the 361057Salm encryption algorithm, see the bdes(1) man page. Encryption/decryption 371057Salm should be fully compatible with SunOS des(1). 3816Salm 391057Salm3) The POSIX interactive global commands `G' and `V' are extended to 401057Salm support multiple commands, including `a', `i' and `c'. The command 411057Salm format is the same as for the global commands `g' and `v', i.e., one 421057Salm command per line with each line, except for the last, ending in a 431057Salm backslash (\). 4416Salm 451057Salm4) An extension to the POSIX file commands `E', `e', `r', `W' and `w' is 461057Salm that <file> arguments are processed for backslash escapes, i.e., any 471057Salm character preceded by a backslash is interpreted literally. If the 481057Salm first unescaped character of a <file> argument is a bang (!), then the 491057Salm rest of the line is interpreted as a shell command, and no escape 501057Salm processing is performed by ed. 5116Salm 521057Salm5) For SunOS ed(1) compatibility, ed runs in restricted mode if invoked 531057Salm as red. This limits editing of files in the local directory only and 541057Salm prohibits shell commands. 5549Salm 561057SalmDEVIATIONS 571057Salm---------- 581057Salm1) Though ed is not a stream editor, it can be used to edit binary files. 591057Salm To assist in binary editing, when a file containing at least one ASCII 601057Salm NUL character is written, a newline is not appended if it did not 611057Salm already contain one upon reading. In particular, reading /dev/null 621057Salm prior to writing prevents appending a newline to a binary file. 6349Salm 641057Salm For example, to create a file with ed containing a single NUL character: 651057Salm $ ed file 661057Salm a 671057Salm ^@ 681057Salm . 691057Salm r /dev/null 701057Salm wq 711057Salm 721057Salm Similarly, to remove a newline from the end of binary `file': 731057Salm $ ed file 741057Salm r /dev/null 751057Salm wq 761057Salm 771057Salm2) Since the behavior of `u' (undo) within a `g' (global) command list is 781057Salm not specified by POSIX, it follows the behavior of the SunOS ed: 791057Salm undo forces a global command list to be executed only once, rather than 801057Salm for each line matching a global pattern. In addtion, each instance of 811057Salm `u' within a global command undoes all previous commands (including 821057Salm undo's) in the command list. This seems the best way, since the 831057Salm alternatives are either too complicated to implement or too confusing 841057Salm to use. 851057Salm 861057Salm The global/undo combination is useful for masking errors that 871057Salm would otherwise cause a script to fail. For instance, an ed script 881057Salm to remove any occurences of either `censor1' or `censor2' might be 891057Salm written as: 901057Salm ed - file <<EOF 911057Salm 1g/.*/u\ 921057Salm ,s/censor1//g\ 931057Salm ,s/censor2//g 941057Salm ... 951057Salm 961057Salm3) The `m' (move) command within a `g' command list also follows the SunOS 971057Salm ed implementation: any moved lines are removed from the global command's 981057Salm `active' list. 991057Salm 1001057Salm4) If ed is invoked with a name argument prefixed by a bang (!), then the 1011057Salm remainder of the argument is interpreted as a shell command. To invoke 1021057Salm ed on a file whose name starts with bang, prefix the name with a 1031057Salm backslash. 104