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