没有文件的Diff

时间:2009-06-13 22:59:34

标签: diff

是否可以在没有物理文件的情况下使用“diff”工具?像这样:

diff "hello" "hell"

1 个答案:

答案 0 :(得分:23)

您可以使用特殊文件名-

将标准输入与文件区分开来
# diff the contents of the file 'some-file' with the string "foobar"
echo foobar | diff - some-file

使用bash,您还可以使用匿名命名管道(有点用词不当)来区分两个管道:

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

另见How can you diff two pipelines with bash?