Vimdiff to compare output instead of files

stdinstdoutvimvimdiff

I am trying to compare two command output (no files)

vimdiff "$(tail /tmp/cachain.pem)" "$(tail /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem)"

I tried playing with redirection, pipe, and vim - -c but I must be missing something. Can anyone help please ?

Best Answer

You are confusing $(…) with <(…). You used the former, which passes the output as arguments to vimdiff. For example, if the last line of /path/to/foo contains bar bar bar, then the following command

echo $(tail -1 /path/to/foo)

is equivalent to

echo bar bar bar

Instead, you need to use <(…). This is called process substitution, and passes the output as a pseudo-file to the vimdiff command. Hence, use the following.

vimdiff <(tail /tmp/cachain.pem) <(tail /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem)

This works in bash and zsh, but apparently there is no way to do process substitution in tcsh.