3

I'm trying to better understand the use of "SHA256SUMS" and "grep." The Ubuntu verify and authenticate tutorial uses the following term: "sha256sum -c SHA256SUMS 2>&1 | grep OK" to verify the download hasn't been corrupted.

I understand it's checking at the SHA256SUMS file that contains two hash values, one for the Desktop version and one for the Live. The usage worked, and I checked it by manually verifying the hash values.

My question is what is the "SHA256SUMS 2>&1" portion doing? Also, it appears to be a part of the "SHA256SUMS" command, though I don't see that usage on the man page I use. Then somehow the result is piped to "grep" to pattern-match with no options.

I'd like to understand it well enough to use the technique in verifying that other software downloads haven't been corrupted.

2

1 Answer 1

3

The grep command is just there to clean up the output for you. The hash checker checks against all the disk images, so the grep command keeps things simple.

With grep: ubuntu-core-16-amd64.img.xz: OK

Without grep: ubuntu-core-16-amd64.img.xz: OK sha256sum: ubuntu-core-16-cm3.img.xz: No such file or directory ubuntu-core-16-cm3.img.xz: FAILED open or read sha256sum: ubuntu-core-16-dragonboard-410c.img.xz: No such file or directory ubuntu-core-16-dragonboard-410c.img.xz: FAILED open or read sha256sum: ubuntu-core-16-dragonboard.img.xz: No such file or directory ubuntu-core-16-dragonboard.img.xz: FAILED open or read sha256sum: ubuntu-core-16-i386.img.xz: No such file or directory ubuntu-core-16-i386.img.xz: FAILED open or read sha256sum: ubuntu-core-16-pi2.img.xz: No such file or directory ubuntu-core-16-pi2.img.xz: FAILED open or read sha256sum: ubuntu-core-16-pi3.img.xz: No such file or directory ubuntu-core-16-pi3.img.xz: FAILED open or read sha256sum: WARNING: 6 listed files could not be read

Update: Sorry, I missed the 2>&1 part of your question. That portion directs any error messages to the same place as the standard output messages. This page explains that quirky idiom: https://www.brianstorti.com/understanding-shell-script-idiom-redirect/

You must log in to answer this question.

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