Diff without files

后端 未结 1 1540
你的背包
你的背包 2021-02-13 00:03

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

diff \"hello\" \"hell\"
相关标签:
1条回答
  • 2021-02-13 00:44

    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?.

    0 讨论(0)
提交回复
热议问题