On Fri, Jul 17, 2020 at 11:35:02PM -0600, Bob Proulx wrote:
> Pádraig Brady wrote:
> > jens wrote:
> > > It would make shell scripts that use sha256sum much simpler. Currently it
> > > is necessary to split the output of sha256sum to obtain the hash, which
> > > usually requires an additional command / Unix process.
> >
> > sum=$(sha256sum file | cut -d ' ' -f 1)
> >
> > Yes that's an extra process, but you can easily
> > enough avoid that on any POSIX shell using:
> >
> > sum=$(sha256sum file) && sum=${sum%% *}
>
> I'll suggest always using stdin instead ("sha256sum < file") as that
> avoids any possible quoting of things to get in the way. In the case
> where the filename contains special characters.
To illustrate this with an example:
$ touch foo\\bar
$ sha256sum foo\\bar
\e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 foo\\bar
$ sha256sum < foo\\bar
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 -
$ sha256sum foo\\bar | cut -d' ' -f1 | sed 's/^\\//'
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
$ sha256sum < foo\\bar | cut -d' ' -f1
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855
The Asterisk ('*') denoting "binary mode" is part of the second whitespace
separated field and can thus be ignored here.
HTH,
Erik
--
La perfection est atteinte non quand il ne reste rien ajouter, mais quand il
ne reste rien à enlever.
-- Antoine de Saint-Exupéry