Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have one file and one input coming from a pipe. They're identical. So why does colordiff report differences?:

echo "123" | colordiff <(echo "123") -
1d0
< 123

It looks that this is colordiff causing the problem. With pure diff, all works OK.

share|improve this question
    
You can try this too: diff <(echo "123") <(echo "123") –  gniourf_gniourf Apr 20 at 13:27
add comment

1 Answer 1

up vote 7 down vote accepted

Using diff

This works for me. Would seem to be an issue with your particular version of diff?

Example

$ echo "123" | diff <(echo "123") -
$

My version

$ diff --version
diff (GNU diffutils) 3.3
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by Paul Eggert, Mike Haertel, David Hayes,
Richard Stallman, and Len Tower.

You could also try this alternative form:

$ diff <(echo "123") <(echo "123")
$

But either way it should report that they're identical.

What about colordiff?

Well this method shows they're the same.

$ colordiff <(echo "123") <(echo "123")
$

However as you've indicated using echo does in fact report these 2 strings as being different:

$ echo "123" | colordiff <(echo "123") -
1d0
< 123

But realize that colordiff is really just a Perl script wrapper around GNU diff.

$ head /usr/bin/colordiff
#!/usr/bin/perl -w

########################################################################
#                                                                      #
# ColorDiff - a wrapper/replacment for 'diff' producing                #
#             colourful output                                         #
#                                                                      #
# Copyright (C)2002-2012 Dave Ewart (davee@sungate.co.uk)              #
#                                                                      #
########################################################################

Since it's a Perl script you can run the script through the Perl debugger to see what's happening:

$ echo "123" | perl -d /usr/bin/colordiff <(echo "123") -

I think the bottom line here is that colordiff is not equipped to take input via STDIN (-), it's only designed to take input from files.

Searching there are several bugs filed regarding the lack of this feature:

Development branch of colordiff

I found this on github, kimmel/colordiff. Looks to be a newer version which handles STDIN better, in my cursory glance at the source.

Alternative forms that work

You can use diff to do the generation of differences and then pipe the output to colordiff afterwards.

$ echo "123" | diff -u <(echo "123") - | colordiff

I found this in daveewart's fork/branch of colordiff, available here on github. There are a fairly large number of other forms that you can call colordiff, perhaps one of those would suit your needs.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.