You are not logged in.
EDIT: The issue is with colordiff, actually, since I have an alias.
I was trying to use diff in a simple script that compares a file with a program's output.
Something wasn't quite right, so I tried:
[pedro@fenix ~][pedro@fenix ~]$ echo "herp" > derp
[pedro@fenix ~]$ diff derp derp
[pedro@fenix ~]$ cat derp | diff derp -
1d0
< herp
[pedro@fenix ~]$ cat derp | diff - derp
0a1
> herp
[pedro@fenix ~]$ cat derp | md5sum
882be39277c094b21e80bb8938d633b7 -
[pedro@fenix ~]$ md5sum derp
882be39277c094b21e80bb8938d633b7 derp
[pedro@fenix ~]$ diff -v
diff (GNU diffutils) 3.2
Copyright © 2011 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.
[pedro@fenix ~]$
Tried the same thing on a different computer with Arch, same results.
Then I tried it on a Fedora box, and got the expected output:
[ra137264@xaveco ~]$ echo "herp" > derp
[ra137264@xaveco ~]$ diff derp derp
[ra137264@xaveco ~]$ cat derp | diff - derp
[ra137264@xaveco ~]$ cat derp | diff derp -
[ra137264@xaveco ~]$ cat derp | md5sum
882be39277c094b21e80bb8938d633b7 -
[ra137264@xaveco ~]$ md5sum derp
882be39277c094b21e80bb8938d633b7 derp
[ra137264@xaveco ~]$ diff -v
diff (GNU diffutils) 3.2
Copyright (C) 2011 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.
[ra137264@xaveco ~]$
What is the reasonable explanation to this behavior?
Last edited by tungsten (2012-04-04 20:17:14)
Offline
$ echo herp > derp
$ diff derp derp
$ cat derp
herp
$ cat derp | diff - derp
$ cat derp | diff derp -
$
Works for me.
Offline
I just realized I have colordiff and "alias diff='colordiff'" in my .bashrc. The issue is with colordiff only.
Offline
Note that if you want to diff with the output of a command, a temporary file is unnecessary. Use process substitution:
$ diff <(seq 2 10) <(seq 1 9)
0a1
> 1
9d9
< 10
Offline
Note that if you want to diff with the output of a command, a temporary file is unnecessary. Use process substitution:
$ diff <(seq 2 10) <(seq 1 9) 0a1 > 1 9d9 < 10
The file I'm comparing with isn't generated by me, it's the expected output of a program I'm supposed to code, given some input:
[pedro@fenix lab05]$ for f in {1..4}; do ./lab05 < arq$f.in | "diff" arq$f.res -; done
[pedro@fenix lab05]$ for f in {1..4}; do ./lab05 < arq$f.in | colordiff arq$f.res -; done
1d0
< 6 6 6 6 6
1d0
< 9 3 0 8 6 4 2 6 5 3 0 8 7 0 8 6 4 2 0
1d0
< 4 5 3 9 1 5 9 9 5 5 5 4 6 0 3 2 9 9
1d0
< 1 1 4 7 7 6 3 6 5 3 5 6 6 0 1 3 0 6 4 1
[pedro@fenix lab05]$ for f in {1..4}; do colordiff arq$f.res <(./lab05 < arq$f.in) ; done
[pedro@fenix lab05]$
So why does it work with that but not with the pipe I'm used to?
Last edited by tungsten (2012-04-04 20:41:22)
Offline
So why does it work with that but not with the pipe I'm used to?
Pipes and process substitution operate quite differently. I guess it comes down to a bug in the colordiff script.
But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner
Offline