On Mon, 01 Nov 2021 21:04:54 -0500, Scott Cheloha wrote: > Yes it would be simpler. However I didn't want to start changing the > input -- which we currently don't do -- without discussing it. > > The standard says we should "write one copy of each input line on the > output." So, if we are being strict, we don't add a newline that isn't > there, because that isn't what we read. Any other interpretation > requires handwaving about what an "input line" even is.
The System V version of uniq actually ignores the last line if it doesn't end in a newline. For example: $ printf "bar\nfoo\nfool" | uniq bar foo AIX, Solaris, and HP-UX still exhibit this behavior. What happens is that the gline() function (which reads the line) returns non-zero when it hits EOF, discarding any input in that line. Interestingly, it does realloc the line buffer as needed to handle long lines. So really, this is a corner case where you can't count on consistent behavior among implementations and we just need to do what we think is best. If you prefer we retain the existing behavior wrt a final line without a newline that is OK with me. - todd