[Toybox] sed N at EOF

Rob Landley rob at landley.net
Mon Sep 12 06:32:01 PDT 2022


Posix says the N command does NOT trigger the default print at EOF:

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sed.html

[2addr]N

  Append the next line of input, less its terminating <newline>, to the pattern
  space, using an embedded <newline> to separate the appended material from the
  original material. Note that the current line number changes.

  If no next line of input is available, the N command verb shall branch to the
  end of the script and quit without starting a new cycle or copying the pattern
  space to standard output.

Except that's not what the gnu/dammit version does:

  $ echo one | sed N
  one
  $ echo -e 'one\none\none' | sed 'N;ax'
  one
  one
  x
  one

Why? (It looks like N acts as "b" at eof, which will do the default print as
normal at end of pattern, but that's not what posix SAID to do...? I implemented
what posix sed. At the time, I thought that was what the gnu/dammit one was
doing too, but apparently not in devuan baywatch?)

Rob


More information about the Toybox mailing list