Search code examples
shelldifftee

diff two pipes originating from one source


I have found the answer how to diff two pipes on SO, and the syntax is showed below.

diff <(./a.out) <(./a.out | sort -n)

However, it would create two processes of a.out, verified by ps. Is it possible to have only one a.out, broadcast the output into two streams, and diff on these two streams?

./a.out | tee >(cat) >(sort -n)

I can do broadcast using tee, but no idea how to use diff then.

Any suggestion?

Edit: Why I don't want to create two processes? The reason is that this is one concurrent program, so the output is non-deterministic. Therefore, I have to use the same output, from one process.


Solution

  • Not sure what your objection is to having 2 processes, but maybe you can use a fifo like this:

    mkfifo fifo
    diff <(./a.out | tee fifo) <(sort < fifo)