3

Consider this:

echo -n a > /tmp/a
echo -n b > /tmp/b
diff -B /tmp/a /tmp/b

Clearly, the two files are different, yet, diff seems to think that the files are identical. I've managed to reproduce this problem on Ubuntu 14.04 with diffutils 3.3, on CloudLinux 5.10 with diffutils 2.8.1, and also Ubuntu 10.04 with diffutils 2.8.1.

If I don't use the -B option, the problem goes away. If the files do end with a newline, the problem goes away. If the files contain more than 1 character, the problem goes away.

I've tried searching the web for an explanation for this behavior but haven't been successful.

Can someone explain what's going on?

And, what is the simplest workaround that I could use for this - the -B behavior is important for me.

Navin
  • 133
  • 5
  • Seems like a reproducible bug then. Report it to the [package maintainer](http://www.gnu.org/software/diffutils/) through the mailinglist or leverage the power of open source and submit a patch after your fix the code yourself. – HBruijn Sep 03 '14 at 09:28
  • 4
    This question appears to be off-topic because it is about reporting a bug and [SF] is not the place to do this. – Sven Sep 03 '14 at 09:29
  • @SvW I don't know whether this is a bug or whether it is known/documented behavior, that is why I asked it here. And also, given the length of time for which this behavior has existed (at least since 2010 if not earlier) it is likely that other people will run into this issue. – Navin Sep 03 '14 at 10:20
  • I understand that. My comment was merely a (somewhat poor) filler for the custom close reason, as @HBruijn already linked you to the maintainer and I agree with both him and Janne that this *is* a bug. – Sven Sep 03 '14 at 10:24
  • @HBruijn thanks. I've reported this as a bug on the diffutils bugs mailing list – Navin Sep 03 '14 at 10:29
  • @Navin Apart from being a bug, this is the kind of thing that would be better at [unix.se] since it's of interest to any unix user and not just professional sysadmins. – Jenny D Sep 03 '14 at 10:34
  • Reproduced in diffutils-3.3. Nice find. – Michael Hampton Sep 03 '14 at 15:51
  • Apparently, it was a bug, and a patch for it has been posted to the bug-diffutils mailing list – Navin Sep 04 '14 at 00:43

1 Answers1

1

Sounds like a bug to me. I tried this with Ubuntu 14.04. Go on and report the bug.

With some of the output modes (ed script, side-by-side) even -B works, but not with the others.

jaba@jaba-ubuntu:~/diffbug$ diff -e -B a b
1c
b
.
diff: a: No newline at end of file

diff: b: No newline at end of file

jaba@jaba-ubuntu:~/diffbug$ diff -y -B a b
a                               bjaba@jaba-ubuntu:~/diffbug$ 
Janne Pikkarainen
  • 31,454
  • 4
  • 56
  • 78