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