commit: 49fc0e9fd47588e9922a91e8938977fafa0a3437
parent 66509f6d38509d3551adaed282e61bea00e5a7f9
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 10 Jan 2026 16:08:26 +0100
cmd/sha*sum: add -q option
Could use grep(1) in most cases but makes it rather complex when
part of conditions.
For example:
if sha256sum -c foobar | grep -v ': OK$'; then
# based on grep's return code rather than sha256sum's
fi
Diffstat:
6 files changed, 27 insertions(+), 9 deletions(-)
diff --git a/cmd/sha1sum.1 b/cmd/sha1sum.1
@@ -9,7 +9,7 @@
.Nd write and verify sha1 checksums
.Sh SYNOPSIS
.Nm
-.Op Fl c
+.Op Fl cq
.Op Ar file...
.Sh DESCRIPTION
.Nm
@@ -25,6 +25,8 @@ Verify checksums contained in each
Currently supported format being checksum, whitespace, an optional asterisk
.Ql *
and finally a filename.
+.It Fl q
+Quiet, do not print 'OK'
.El
.Sh EXIT STATUS
.Ex -std
diff --git a/cmd/sha1sum.c b/cmd/sha1sum.c
@@ -20,6 +20,7 @@
#define SHA1SUM_LEN SHA1_DIGEST_LENGTH * 2 + 1
const char *argv0 = "sha1sum";
+bool quiet = false;
static int
sha1sum(int fd, const char *fdname, char sum[SHA1SUM_LEN])
@@ -146,7 +147,7 @@ check(FILE *file, const char *filename)
if(sha1sum(fd, target, got) < 0) err = 1;
if(memcmp(line, got, SHA1SUM_LEN) == 0)
{
- printf("%s: OK\n", target);
+ if(!quiet) printf("%s: OK\n", target);
}
else
{
@@ -182,13 +183,16 @@ main(int argc, char *argv[])
{
bool opt_c = false;
- for(int c = -1; (c = getopt_nolong(argc, argv, ":c")) != -1;)
+ for(int c = -1; (c = getopt_nolong(argc, argv, ":cq")) != -1;)
{
switch(c)
{
case 'c':
opt_c = true;
break;
+ case 'q':
+ quiet = true;
+ break;
case ':':
fprintf(stderr, "%s: error: Missing operand for option: '-%c'\n", argv0, optopt);
return 1;
diff --git a/cmd/sha256sum.1 b/cmd/sha256sum.1
@@ -9,7 +9,7 @@
.Nd write and verify sha256 checksums
.Sh SYNOPSIS
.Nm
-.Op Fl c
+.Op Fl cq
.Op Ar file...
.Sh DESCRIPTION
.Nm
@@ -25,6 +25,8 @@ Verify checksums contained in each
Currently supported format being checksum, whitespace, an optional asterisk
.Ql *
and finally a filename.
+.It Fl q
+Quiet, do not print 'OK'
.El
.Sh EXIT STATUS
.Ex -std
diff --git a/cmd/sha256sum.c b/cmd/sha256sum.c
@@ -20,6 +20,7 @@
#define SHA256SUM_LEN SHA256_DIGEST_LENGTH * 2 + 1
const char *argv0 = "sha256sum";
+bool quiet = false;
static int
sha256sum(int fd, const char *fdname, char sum[SHA256SUM_LEN])
@@ -146,7 +147,7 @@ check(FILE *file, const char *filename)
if(sha256sum(fd, target, got) < 0) err = 1;
if(memcmp(line, got, SHA256SUM_LEN) == 0)
{
- printf("%s: OK\n", target);
+ if(!quiet) printf("%s: OK\n", target);
}
else
{
@@ -182,13 +183,16 @@ main(int argc, char *argv[])
{
bool opt_c = false;
- for(int c = -1; (c = getopt_nolong(argc, argv, ":c")) != -1;)
+ for(int c = -1; (c = getopt_nolong(argc, argv, ":cq")) != -1;)
{
switch(c)
{
case 'c':
opt_c = true;
break;
+ case 'q':
+ quiet = true;
+ break;
case ':':
fprintf(stderr, "%s: error: Missing operand for option: '-%c'\n", argv0, optopt);
return 1;
diff --git a/cmd/sha512sum.1 b/cmd/sha512sum.1
@@ -9,7 +9,7 @@
.Nd write and verify sha512 checksums
.Sh SYNOPSIS
.Nm
-.Op Fl c
+.Op Fl cq
.Op Ar file...
.Sh DESCRIPTION
.Nm
@@ -25,6 +25,8 @@ Verify checksums contained in each
Currently supported format being checksum, whitespace, an optional asterisk
.Ql *
and finally a filename.
+.It Fl q
+Quiet, do not print 'OK'
.El
.Sh EXIT STATUS
.Ex -std
diff --git a/cmd/sha512sum.c b/cmd/sha512sum.c
@@ -20,6 +20,7 @@
#define SHA512SUM_LEN SHA512_DIGEST_LENGTH * 2 + 1
const char *argv0 = "sha512sum";
+bool quiet = false;
static int
sha512sum(int fd, const char *fdname, char sum[SHA512SUM_LEN])
@@ -146,7 +147,7 @@ check(FILE *file, const char *filename)
if(sha512sum(fd, target, got) < 0) err = 1;
if(memcmp(line, got, SHA512SUM_LEN) == 0)
{
- printf("%s: OK\n", target);
+ if(!quiet) printf("%s: OK\n", target);
}
else
{
@@ -182,13 +183,16 @@ main(int argc, char *argv[])
{
bool opt_c = false;
- for(int c = -1; (c = getopt_nolong(argc, argv, ":c")) != -1;)
+ for(int c = -1; (c = getopt_nolong(argc, argv, ":cq")) != -1;)
{
switch(c)
{
case 'c':
opt_c = true;
break;
+ case 'q':
+ quiet = true;
+ break;
case ':':
fprintf(stderr, "%s: error: Missing operand for option: '-%c'\n", argv0, optopt);
return 1;