21

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 ?

2 Answers 2

36

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.

7
  • this is only in bash, though
    – simona
    Commented May 31, 2018 at 11:10
  • @simona Works for me in zsh too. Probably csh and tcsh as well.
    – Sparhawk
    Commented May 31, 2018 at 12:27
  • @Sparhawk it doesn't work in tcsh
    – simona
    Commented May 31, 2018 at 15:47
  • @simona Thanks for that information; I'm not familiar with tcsh. You might consider putting up an answer that works in tsch. Cheers.
    – Sparhawk
    Commented Jun 1, 2018 at 1:59
  • @Sparhawk apparently there is no way to this in tcsh without creating a file unix.stackexchange.com/questions/5111/…
    – simona
    Commented Jun 1, 2018 at 15:07
0

In fish shell, the psub command performs process substitution, so your example would be:

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

By the way, I think editing a file in comparison with a specific Git revision of that file is a particularly useful case of process substitution and vimdiff. Define (in fish syntax, but easily adaptable to POSIX shell syntax)

function vimgitdiff
    vimdiff $argv[1] (git show $argv[2]:$argv[1] | psub)
end

then call

vimgitdiff path/to/file branch-name

to open Vim with path/to/file as currently in the working tree on the left and as on branch-name on the right.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .