, Johann Schmitz

Today I came across the problem that I needed to create the checksum of a file before and after compressing it with bzip2. Since the file can be quite large, i didn't wanted to create the input checksum, compress the file and create the checksum of the output file afterwards as this would involve to read the data three times.

But thanks to some trickery this can be accomplish by duplicating the stdin:

f="some-file.bin"; dd if=${f} status=none > >(tee >(sha512sum - > ${f}.sha512)) | bzip2 | tee >(sha512sum - >> ${f}.sha512) > ${f}.bz2