Is there a Bash one-liner to check that the output of three commands match?

bash

Solution

`cmp -s <( cmd1) <(cmd2) && cmp -s <( cmd1) <(cmd3)`

Note that this construct executes cmd1 two times.

If you require single exec of each cmd, more complicated line would look something like:

`cmd1|tee >( cmp -s <(cmd2) )|cmp -s <(cmd3)`

Also for the second one, checking the result is complicated (you have to check `PIPESTATUS` array)

Problem

I'm trying to figure out some Bash-foo to check that the output of three different commands is identical. I can do this with several lines of a Bash script, I'm just wondering if what I want to do is possible in one line with some fancy shell I/O redirection. What I want to do is check that an SSL certificate matches up with a particular key and certificate signing request. The commands look like this: ``` openssl x509 -noout -modulus -in certificate.crt | openssl md5 openssl rsa -noout -modulus -in privateKey.key | openssl md5 openssl req -noout -modulus -in CSR.csr | openssl md5 ``` If the key, cert, and csr match up, all three of those commands should spit out identical output, like: "(stdin)= 95ce143e8418cf8a4f7dd718983ed4eb". Here's a prototype: ``` [[ $(echo -e "blah\nblah\nblah" | uniq | wc -l) -eq 1 ]] ``` But I can't get from there to the final product. This doesn't work: ``` [[ $(openssl x509 -noout -modulus -in certificate.crt | openssl md5 && openssl rsa -noout -modulus -in privateKey.key | openssl md5 && openssl req -noout -modulus -in CSR.csr | openssl md5 | uniq | wc -l) -eq 1 ]] ``` One problem is maybe that my prototype generates all three lines of output from one command, but the real thing uses `&&` a couple times.

Original source