1 1.11 andvar $NetBSD: POSIX,v 1.11 2022/05/20 07:47:16 andvar Exp $ 2 1.9 cgd 3 1.7 alm This version of ed(1) is not strictly POSIX compliant, as described in 4 1.7 alm the POSIX 1003.2 document. The following is a summary of the omissions, 5 1.7 alm extensions and possible deviations from POSIX 1003.2. 6 1.7 alm 7 1.7 alm OMISSIONS 8 1.7 alm --------- 9 1.7 alm 1) Locale(3) is not supported yet. 10 1.7 alm 11 1.7 alm 2) For backwards compatibility, the POSIX rule that says a range of 12 1.7 alm addresses cannot be used where only a single address is expected has 13 1.7 alm been relaxed. 14 1.7 alm 15 1.8 alm 3) To support the BSD `s' command (see extension [1] below), 16 1.8 alm substitution patterns cannot be delimited by numbers or the characters 17 1.11 andvar `r', `g' and `p'. In contrast, POSIX specifies any character except 18 1.11 andvar space or newline can be used as a delimiter. 19 1.8 alm 20 1.7 alm EXTENSIONS 21 1.7 alm ---------- 22 1.7 alm 1) BSD commands have been implemented wherever they do not conflict with 23 1.7 alm the POSIX standard. The BSD-ism's included are: 24 1.8 alm i) `s' (i.e., s[n][rgp]*) to repeat a previous substitution, 25 1.7 alm ii) `W' for appending text to an existing file, 26 1.7 alm iii) `wq' for exiting after a write, 27 1.7 alm iv) `z' for scrolling through the buffer, and 28 1.11 andvar v) BSD line addressing syntax (i.e., `^' and `%') is recognized. 29 1.7 alm 30 1.7 alm 2) If crypt(3) is available, files can be read and written using DES 31 1.7 alm encryption. The `x' command prompts the user to enter a key used for 32 1.11 andvar encrypting/decrypting subsequent reads and writes. If only a newline 33 1.7 alm is entered as the key, then encryption is disabled. Otherwise, a key 34 1.7 alm is read in the same manner as a password entry. The key remains in 35 1.7 alm effect until encryption is disabled. For more information on the 36 1.7 alm encryption algorithm, see the bdes(1) man page. Encryption/decryption 37 1.8 alm should be fully compatible with SunOS des(1). 38 1.7 alm 39 1.7 alm 3) The POSIX interactive global commands `G' and `V' are extended to 40 1.7 alm support multiple commands, including `a', `i' and `c'. The command 41 1.7 alm format is the same as for the global commands `g' and `v', i.e., one 42 1.7 alm command per line with each line, except for the last, ending in a 43 1.7 alm backslash (\). 44 1.7 alm 45 1.8 alm 4) An extension to the POSIX file commands `E', `e', `r', `W' and `w' is 46 1.7 alm that <file> arguments are processed for backslash escapes, i.e., any 47 1.7 alm character preceded by a backslash is interpreted literally. If the 48 1.7 alm first unescaped character of a <file> argument is a bang (!), then the 49 1.7 alm rest of the line is interpreted as a shell command, and no escape 50 1.7 alm processing is performed by ed. 51 1.7 alm 52 1.8 alm 5) For SunOS ed(1) compatibility, ed runs in restricted mode if invoked 53 1.7 alm as red. This limits editing of files in the local directory only and 54 1.7 alm prohibits shell commands. 55 1.7 alm 56 1.7 alm DEVIATIONS 57 1.7 alm ---------- 58 1.8 alm 1) Though ed is not a stream editor, it can be used to edit binary files. 59 1.8 alm To assist in binary editing, when a file containing at least one ASCII 60 1.8 alm NUL character is written, a newline is not appended if it did not 61 1.8 alm already contain one upon reading. In particular, reading /dev/null 62 1.8 alm prior to writing prevents appending a newline to a binary file. 63 1.8 alm 64 1.8 alm For example, to create a file with ed containing a single NUL character: 65 1.8 alm $ ed file 66 1.8 alm a 67 1.8 alm ^@ 68 1.8 alm . 69 1.8 alm r /dev/null 70 1.8 alm wq 71 1.8 alm 72 1.8 alm Similarly, to remove a newline from the end of binary `file': 73 1.8 alm $ ed file 74 1.8 alm r /dev/null 75 1.8 alm wq 76 1.8 alm 77 1.8 alm 2) Since the behavior of `u' (undo) within a `g' (global) command list is 78 1.8 alm not specified by POSIX, it follows the behavior of the SunOS ed: 79 1.8 alm undo forces a global command list to be executed only once, rather than 80 1.11 andvar for each line matching a global pattern. In addition, each instance of 81 1.8 alm `u' within a global command undoes all previous commands (including 82 1.8 alm undo's) in the command list. This seems the best way, since the 83 1.8 alm alternatives are either too complicated to implement or too confusing 84 1.11 andvar to use. 85 1.8 alm 86 1.8 alm The global/undo combination is useful for masking errors that 87 1.8 alm would otherwise cause a script to fail. For instance, an ed script 88 1.10 kristerw to remove any occurrences of either `censor1' or `censor2' might be 89 1.8 alm written as: 90 1.8 alm ed - file <<EOF 91 1.8 alm 1g/.*/u\ 92 1.8 alm ,s/censor1//g\ 93 1.8 alm ,s/censor2//g 94 1.8 alm ... 95 1.7 alm 96 1.8 alm 3) The `m' (move) command within a `g' command list also follows the SunOS 97 1.7 alm ed implementation: any moved lines are removed from the global command's 98 1.7 alm `active' list. 99 1.7 alm 100 1.8 alm 4) If ed is invoked with a name argument prefixed by a bang (!), then the 101 1.7 alm remainder of the argument is interpreted as a shell command. To invoke 102 1.7 alm ed on a file whose name starts with bang, prefix the name with a 103 1.7 alm backslash. 104