This is really a POSIX bug which GNU ed has implemented.

From: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/ed.html

[Commands in ed]

... any command (except e, E, f, q, Q, r, w, and !) can be SUFFIXED by
the letter l, n, or p

(emphasis mine)

[Substitute Command]

(.,.)s/RE/replacement/flags

... flags is zero or more of:

count
g
l
n
p

------------------

The problem is that the two sections "Commands in ed" and "Substitute
Command" are in conflict.

To illustrate why this is bad, consider the m (move),  t (copy) or k (mark)
commands. To copy the current line to after the last and print the new
line, it doesn't make sense to say: `tp$'. The correct syntax is:
`t$p'. Similarly, the mark command syntax is `kxp' not `kpx'.
Fortunately, GNU ed prints an error in the case of `tp$' and `kpx'. And in the
interest of clarity and consistency, the substitute command should
also not allow permuting addresses and print flags. Unfortunately,
GNU ed (and GNU sed) will happily execute `s/old/new/p2'.  The command
is `s/old/new/2' with a print suffix, not `s/old/new/p' with a 2
suffix.

Generally, POSIX has been leaning toward more permissible syntax, but
in this case it is just a documentation error which POSIX needs to clarify.

GNU sed can more easily get away with this because it doesn't
implement `t', `m' or `k' commands.



Reply via email to