sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit f0f12468ef8a2710533df7a2bb55b426c1b46d86
parent 5800c117e2744b00d32f747fab123eb581bb4722
Author: Mattias Andrée <maandree@kth.se>
Date:   Wed Mar 30 01:16:27 +0200

printenv: exit status is 2 on failure

This provides a reliable and portable way to
test whether an environment variable is defined.

(Of course, if you are using glibc you may get
false positives if you include a = in the query.)

Signed-off-by: Mattias Andrée <maandree@kth.se>

Diffstat:
printenv.1 | 11++++++++++-
printenv.c | 2+-
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/printenv.1 b/printenv.1 @@ -1,4 +1,4 @@ -.Dd 2015-10-08 +.Dd 2016-03-30 .Dt PRINTENV 1 .Os sbase .Sh NAME @@ -16,5 +16,14 @@ is given. Otherwise, prints only the value of each .Ar var one per line in the order specified. +.SH EXIT STATUS +.Bl -tag -width Ds +.It 0 +Successful completion. +.It 1 +One or more queried variables were not found. +.It > 1 +An error occurred. +.El .Sh SEE ALSO .Xr env 1 diff --git a/printenv.c b/printenv.c @@ -26,5 +26,5 @@ main(int argc, char *argv[]) } } - return fshut(stdout, "<stdout>") || ret; + return fshut(stdout, "<stdout>") ? 2 : ret; }