Search code examples
bashshelldockersha256sha

How to use sha256sum --check option to fail if incorrect hash on a docker script


I'm writing a docker script and therefore I cannot rely on bash scripts. I need the docker script to fail if the sha256sum of a downloaded file (though wget) hash is incorrect. I see that there exists a check option in sha256sum, but I can't find how to use it.

It's something like sha256sum -c hash file but it won't work for me. I think I actually must supply a file to -c, something like using echo.


Solution

  • Two Examples:

    sha256sum /etc/passwd > checksum
    sha256sum -c checksum
    

    Output:

    /etc/passwd: OK
    

    or

    sha256sum /etc/passwd > checksum
    sha256sum --status -c checksum
    echo "$?"
    

    Output:

    0