没有文件的Diff

Ver*_*gen 15 diff

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

diff "hello" "hell"
Run Code Online (Sandbox Code Playgroud)

Ada*_*eld 23

您可以使用特殊文件名将标准输入与文件区分开来-:

# diff the contents of the file 'some-file' with the string "foobar"
echo foobar | diff - some-file
Run Code Online (Sandbox Code Playgroud)

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

# diff the string "foo" with the string "baz"
diff <(echo foo) <(echo baz)
Run Code Online (Sandbox Code Playgroud)

另请参见如何使用bash区分两个管道?.