xref: /freebsd/bin/ed/POSIX (revision 732a02b4e77866604a120a275c082bb6221bd2ff)
1$FreeBSD$
2
3This version of ed(1) is not strictly POSIX compliant, as described in
4the POSIX 1003.2 document.  The following is a summary of the omissions,
5extensions and possible deviations from POSIX 1003.2.
6
7OMISSIONS
8---------
91) For backwards compatibility, the POSIX rule that says a range of
10   addresses cannot be used where only a single address is expected has
11   been relaxed.
12
132) To support the BSD `s' command (see extension [1] below),
14   substitution patterns cannot be delimited by numbers or the characters
15   `r', `g' and `p'.  In contrast, POSIX specifies any character expect
16   space or newline can used as a delimiter.
17
18EXTENSIONS
19----------
201) BSD commands have been implemented wherever they do not conflict with
21   the POSIX standard.  The BSD-ism's included are:
22	i) `s' (i.e., s[n][rgp]*) to repeat a previous substitution,
23	ii) `W' for appending text to an existing file,
24	iii) `wq' for exiting after a write,
25	iv) `z' for scrolling through the buffer, and
26	v) BSD line addressing syntax (i.e., `^' and `%')  is recognized.
27
282) The POSIX interactive global commands `G' and `V' are extended to
29   support multiple commands, including `a', `i' and `c'.  The command
30   format is the same as for the global commands `g' and `v', i.e., one
31   command per line with each line, except for the last, ending in a
32   backslash (\).
33
343) An extension to the POSIX file commands `E', `e', `r', `W' and `w' is
35   that <file> arguments are processed for backslash escapes, i.e.,  any
36   character preceded by a backslash is interpreted literally.  If the
37   first unescaped character of a <file> argument is a bang (!), then the
38   rest of the line is interpreted as a shell command, and no escape
39   processing is performed by ed.
40
414) For SunOS ed(1) compatibility, ed runs in restricted mode if invoked
42   as red.  This limits editing of files in the local directory only and
43   prohibits shell commands.
44
45DEVIATIONS
46----------
471) Though ed is not a stream editor, it can be used to edit binary files.
48   To assist in binary editing, when a file containing at least one ASCII
49   NUL character is written, a newline is not appended if it did not
50   already contain one upon reading.  In particular, reading /dev/null
51   prior to writing prevents appending a newline to a binary file.
52
53   For example, to create a file with ed containing a single NUL character:
54      $ ed file
55      a
56      ^@
57      .
58      r /dev/null
59      wq
60
61    Similarly, to remove a newline from the end of binary `file':
62      $ ed file
63      r /dev/null
64      wq
65
662) Since the behavior of `u' (undo) within a `g' (global) command list is
67   not specified by POSIX, it follows the behavior of the SunOS ed:
68   undo forces a global command list to be executed only once, rather than
69   for each line matching a global pattern.  In addition, each instance of
70   `u' within a global command undoes all previous commands (including
71   undo's) in the command list.  This seems the best way, since the
72   alternatives are either too complicated to implement or too confusing
73   to use.
74
75   The global/undo combination is useful for masking errors that
76   would otherwise cause a script to fail.  For instance, an ed script
77   to remove any occurrences of either `censor1' or `censor2' might be
78   written as:
79   	ed - file <<EOF
80	1g/.*/u\
81	,s/censor1//g\
82	,s/censor2//g
83	...
84
853) The `m' (move) command within a `g' command list also follows the SunOS
86   ed implementation: any moved lines are removed from the global command's
87   `active' list.
88
894) If ed is invoked with a name argument prefixed by a bang (!), then the
90   remainder of the argument is interpreted as a shell command.  To invoke
91   ed on a file whose name starts with bang, prefix the name with a
92   backslash.
93