bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#31493: please add null-terminated line output for sha256sum, sha1sum


From: Pádraig Brady
Subject: bug#31493: please add null-terminated line output for sha256sum, sha1sum, etc
Date: Sun, 10 Jun 2018 18:02:02 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

On 18/05/18 07:49, Daniel Kahn Gillmor wrote:
> Hi GNU coreutils developers!
> 
> This is a feature request for the hashing/digesting tools in coreutils,
> like sha256sum, sha1sum, md5sum, etc.
> 
> currently, those tools emit line-oriented output about the files that
> they hash.  if a file has a newline in the name, those tools emit output
> with a leading /, like so:
> 
> 0 address@hidden:~$ sha256sum a*
> 348df4eb47f9230bfe89637afe7409bec883424d822257b6cbbce93ee780d992  a
> 98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4  a   b
> \98ea6e4f216f2fb4b69fff9b3a44842c38686ca685f3f55dc48c5d3fb1107be4  a\nb\n
> 0 address@hidden:~$ 
> 
> most users of sha256sum (etc) in shell scripts probably are unaware of
> this behavior and just cross their fingers and hope no file has a
> newline in its filename.
> 
> However, other common tools have processing options that use
> NUL-terminated records. For example, sort (-z) and find (-print0) and
> xargs (-0)
> 
> It would be nice if sha256sum (etc) had a comparable functionality to be
> able to fit better into pipelines with these other tools.
> 
> So i'm proposing a flag -z, --zero-terminated for these tools that
> alters the output (and input) format, to use NUL chars instead of
> newlines.  presumably when that flag is used, the emitted data should
> *not* be backslash-escaped.

I used --zero rather than --zero-terminated like other tools that
only change _output_ format with -z, rather than supporting it also
as an _input_ format. It would complicate the processing to support
--check of input with --zero, with no added functionality.
Having --check support this format, would also an incompat with
older versions of these tools.

As an example of processing now possible, the following would
robustly pass duplicate files to xargs for processing:

  $ md5sum src/md5sum.{c,c} -z |
    sort -z | uniq -z -d -w32 | cut -z -c35- |
    xargs -r0

    src/md5sum.c

cheers,
Pádraig

Attachment: md5sum--zero.patch
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]