1*75b8c1c8Sandvar$NetBSD: POSIX,v 1.11 2022/05/20 07:47:16 andvar Exp $ 249f0ad86Scgd 39380925bSalmThis version of ed(1) is not strictly POSIX compliant, as described in 49380925bSalmthe POSIX 1003.2 document. The following is a summary of the omissions, 59380925bSalmextensions and possible deviations from POSIX 1003.2. 620d73299Salm 79380925bSalmOMISSIONS 89380925bSalm--------- 99380925bSalm1) Locale(3) is not supported yet. 1020d73299Salm 119380925bSalm2) For backwards compatibility, the POSIX rule that says a range of 129380925bSalm addresses cannot be used where only a single address is expected has 139380925bSalm been relaxed. 1420d73299Salm 151357f155Salm3) To support the BSD `s' command (see extension [1] below), 161357f155Salm substitution patterns cannot be delimited by numbers or the characters 17*75b8c1c8Sandvar `r', `g' and `p'. In contrast, POSIX specifies any character except 18*75b8c1c8Sandvar space or newline can be used as a delimiter. 191357f155Salm 209380925bSalmEXTENSIONS 219380925bSalm---------- 229380925bSalm1) BSD commands have been implemented wherever they do not conflict with 239380925bSalm the POSIX standard. The BSD-ism's included are: 241357f155Salm i) `s' (i.e., s[n][rgp]*) to repeat a previous substitution, 259380925bSalm ii) `W' for appending text to an existing file, 269380925bSalm iii) `wq' for exiting after a write, 279380925bSalm iv) `z' for scrolling through the buffer, and 289380925bSalm v) BSD line addressing syntax (i.e., `^' and `%') is recognized. 2920d73299Salm 309380925bSalm2) If crypt(3) is available, files can be read and written using DES 319380925bSalm encryption. The `x' command prompts the user to enter a key used for 329380925bSalm encrypting/decrypting subsequent reads and writes. If only a newline 339380925bSalm is entered as the key, then encryption is disabled. Otherwise, a key 349380925bSalm is read in the same manner as a password entry. The key remains in 359380925bSalm effect until encryption is disabled. For more information on the 369380925bSalm encryption algorithm, see the bdes(1) man page. Encryption/decryption 371357f155Salm should be fully compatible with SunOS des(1). 3820d73299Salm 399380925bSalm3) The POSIX interactive global commands `G' and `V' are extended to 409380925bSalm support multiple commands, including `a', `i' and `c'. The command 419380925bSalm format is the same as for the global commands `g' and `v', i.e., one 429380925bSalm command per line with each line, except for the last, ending in a 439380925bSalm backslash (\). 4420d73299Salm 451357f155Salm4) An extension to the POSIX file commands `E', `e', `r', `W' and `w' is 469380925bSalm that <file> arguments are processed for backslash escapes, i.e., any 479380925bSalm character preceded by a backslash is interpreted literally. If the 489380925bSalm first unescaped character of a <file> argument is a bang (!), then the 499380925bSalm rest of the line is interpreted as a shell command, and no escape 509380925bSalm processing is performed by ed. 519380925bSalm 521357f155Salm5) For SunOS ed(1) compatibility, ed runs in restricted mode if invoked 539380925bSalm as red. This limits editing of files in the local directory only and 549380925bSalm prohibits shell commands. 559380925bSalm 569380925bSalmDEVIATIONS 579380925bSalm---------- 581357f155Salm1) Though ed is not a stream editor, it can be used to edit binary files. 591357f155Salm To assist in binary editing, when a file containing at least one ASCII 601357f155Salm NUL character is written, a newline is not appended if it did not 611357f155Salm already contain one upon reading. In particular, reading /dev/null 621357f155Salm prior to writing prevents appending a newline to a binary file. 63aef94df1Salm 641357f155Salm For example, to create a file with ed containing a single NUL character: 651357f155Salm $ ed file 661357f155Salm a 671357f155Salm ^@ 681357f155Salm . 691357f155Salm r /dev/null 701357f155Salm wq 711357f155Salm 721357f155Salm Similarly, to remove a newline from the end of binary `file': 731357f155Salm $ ed file 741357f155Salm r /dev/null 751357f155Salm wq 761357f155Salm 771357f155Salm2) Since the behavior of `u' (undo) within a `g' (global) command list is 781357f155Salm not specified by POSIX, it follows the behavior of the SunOS ed: 791357f155Salm undo forces a global command list to be executed only once, rather than 80*75b8c1c8Sandvar for each line matching a global pattern. In addition, each instance of 811357f155Salm `u' within a global command undoes all previous commands (including 821357f155Salm undo's) in the command list. This seems the best way, since the 831357f155Salm alternatives are either too complicated to implement or too confusing 841357f155Salm to use. 851357f155Salm 861357f155Salm The global/undo combination is useful for masking errors that 871357f155Salm would otherwise cause a script to fail. For instance, an ed script 883d173ac8Skristerw to remove any occurrences of either `censor1' or `censor2' might be 891357f155Salm written as: 901357f155Salm ed - file <<EOF 911357f155Salm 1g/.*/u\ 921357f155Salm ,s/censor1//g\ 931357f155Salm ,s/censor2//g 941357f155Salm ... 951357f155Salm 961357f155Salm3) The `m' (move) command within a `g' command list also follows the SunOS 97aef94df1Salm ed implementation: any moved lines are removed from the global command's 98aef94df1Salm `active' list. 999380925bSalm 1001357f155Salm4) If ed is invoked with a name argument prefixed by a bang (!), then the 1019380925bSalm remainder of the argument is interpreted as a shell command. To invoke 1029380925bSalm ed on a file whose name starts with bang, prefix the name with a 1039380925bSalm backslash. 104