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