bashfilediff

Diff output from two programs without temporary files


Say I have too programs a and b that I can run with ./a and ./b.

Is it possible to diff their outputs without first writing to temporary files?


Solution

  • Use <(command) to pass one command's output to another program as if it were a file name. Bash pipes the program's output to a pipe and passes a file name like /dev/fd/63 to the outer command.

    diff <(./a) <(./b)
    

    Similarly you can use >(command) if you want to pipe something into a command.

    This is called "Process Substitution" in Bash's man page.

    While process substitution is not POSIX, it is supported by bash, ksh, and zsh. (ref: SE's network answer by John1024 or comment by Gilles 'SO- stop being evil')