Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Diff without files

Tags:

diff

Is it possible to use the "diff" tool without having physical files? Something like this:

diff "hello" "hell"
like image 488
Verhogen Avatar asked Jun 13 '09 22:06

Verhogen


1 Answers

You can diff standard input with a file by using the special filename -:

# diff the contents of the file 'some-file' with the string "foobar"
echo foobar | diff - some-file

With bash, you can also use anonymous named pipes (a bit of a misnomer) to diff two pipelines:

# diff the string "foo" with the string "baz"
diff <(echo foo) <(echo baz)

See also How can you diff two pipelines with bash?.

like image 119
Adam Rosenfield Avatar answered Oct 02 '22 17:10

Adam Rosenfield