tags:

views:

135

answers:

2

How come I can do this in bash:

$ diff -u <(echo -e "line1\nline2") <(echo -e "line1\nline3")
--- /dev/fd/63  2009-03-30 09:49:07.527272646 +0100
+++ /dev/fd/62  2009-03-30 09:49:07.527272646 +0100
@@ -1,2 +1,2 @@
 line1
-line2
+line3

i.e. I can use named pipes / process substituion to get the diff of a small chunk of text. However when I try to do it with wdiff, the diff for words, not just lines, I get no useful output

wdiff <(echo -e "line1\nline2") <(echo -e "line1\nline3")
[--]{++}

UPDATE: looks like there's an existing ubuntu bug report for this: https://bugs.launchpad.net/ubuntu/+source/wdiff/+bug/160912

A: 

My guess would be that wdiff is broken.

Mark Probst
Funny that this answer should be voted down, considering that the accepted answer gives evidence that wdiff is, indeed, broken.
Mark Probst
That's probably because the mere statement doesn't help a lot (note that I didn't downvote).
Joachim Sauer
+8  A: 

An strace reveals that wdiff stats the files (probably to find out their size). Since named pipes report a size of 0 it probably assumes that both files are empty and therefore equal:

$ strace -efile wdiff -1 <(echo -e "line1\nline2") <(echo -e "line1\nline3")
execve("/usr/bin/wdiff", ["wdiff", "-1", "/dev/fd/63", "/dev/fd/62"], [/* 44 vars */]) = 0
[snip uninteresting stuff]
stat64("/dev/fd/63", {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
open("/dev/fd/63", O_RDONLY)            = 3
open("/tmp/wdiff.MzPXmH", O_RDWR|O_CREAT|O_EXCL, 0600) = 4
stat64("/dev/fd/62", {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
open("/dev/fd/62", O_RDONLY)            = 4
open("/tmp/wdiff.5nma9j", O_RDWR|O_CREAT|O_EXCL, 0600) = 5
--- SIGCHLD (Child exited) @ 0 (0) ---
unlink("/tmp/wdiff.MzPXmH")             = 0
unlink("/tmp/wdiff.5nma9j")             = 0
{++}Process 27699 detached

Edit: also note that bash may use /dev/fd-style filenames instead of named pipes if the kernel supports it (most recent ones do, the example above shows this), but the effect is pretty much the same.

Joachim Sauer
Yeah, reproduced.
Tim Post
I can reproduce aswell. diff stats the files aswell, but it still works.
Rory