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