>From `man ed`

  If replacement consists of a single `%', then
  replacement from the last substitution is used

However, there seems to be a bug in this if the closing delimiter isn't
provided.

Normally the closing replacement delimiter is optional:

  s/foo/bar/
  s/foo/bar

(both replace "foo" with "bar") However using "%" per the man-page seems
to require the closing delimiter.  To demonstrate

  $ cat test.txt
  a
  b
  c

  $ ed test.txt
  6
  1s/a/hello
  hello
  2/s/b/%
  %
  ,n
  1       hello
  2       %
  3       c
  Q

  $ ed test.txt
  6
  1s/a/hello
  hello
  2/s/b/%/
  ,n
  1       hello
  2       hello
  3       c
  Q

So the biggest issue is that, without the trailing slash, it replaces
with "%" rather than the last replacement text.  As a minor side-note,
when using the most recent replacement (with the slash), it doesn't
print the resulting line the same way it does with a normal substitution
(i.e., note that the first example prints the "%", while the second
emits nothing)

It looks like src/bin/ed/sub.c:89 has the test

  if (*ibufp == '%' && *(ibufp + 1) == delimiter) {

which should likely be something like (untested)

  if (*ibufp == '%' && (*(ibufp + 1) == delimiter || *(ibufp + 1) == '\0')) {

FWIW, this bug appears in FreeBSD's ed(1) as well
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=284434

Thanks!

-tkc
-- 





Reply via email to