summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorKlemens Nanni <kn@cvs.openbsd.org>2024-07-28 10:08:45 +0000
committerKlemens Nanni <kn@cvs.openbsd.org>2024-07-28 10:08:45 +0000
commitde715afd00667db995b0400db76244bad123ab88 (patch)
treecb3497f98f99a2e643d088f6e921e8462274eb2a /usr.bin
parent8b7f8e5126ebc6e6eeb7c4ca86abb65c3a11b0ec (diff)
Support "-u name" to remove variable from environment
OK aisha millert Feedback jmc
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/env/env.112
-rw-r--r--usr.bin/env/env.c10
2 files changed, 17 insertions, 5 deletions
diff --git a/usr.bin/env/env.1 b/usr.bin/env/env.1
index 050a8c6c73f..db35cb73a04 100644
--- a/usr.bin/env/env.1
+++ b/usr.bin/env/env.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: env.1,v 1.20 2015/01/12 21:42:53 deraadt Exp $
+.\" $OpenBSD: env.1,v 1.21 2024/07/28 10:08:44 kn Exp $
.\" Copyright (c) 1980, 1990 The Regents of the University of California.
.\" All rights reserved.
.\"
@@ -30,7 +30,7 @@
.\"
.\" from: @(#)printenv.1 6.7 (Berkeley) 7/28/91
.\"
-.Dd $Mdocdate: January 12 2015 $
+.Dd $Mdocdate: July 28 2024 $
.Dt ENV 1
.Os
.Sh NAME
@@ -39,6 +39,7 @@
.Sh SYNOPSIS
.Nm env
.Op Fl i
+.Op Fl u Ar name
.Oo
.Ar name Ns = Ns Ar value ...
.Oc
@@ -66,6 +67,10 @@ The options are as follows:
Causes
.Nm
to completely ignore the environment it inherits.
+.It Fl u Ar name
+Remove
+.Ar name
+from the environment.
.El
.Pp
If no
@@ -121,6 +126,9 @@ The
utility is compliant with the
.St -p1003.1-2008
specification.
+The flag
+.Op Fl u
+is an extension to that specification.
.Pp
The historic
.Fl
diff --git a/usr.bin/env/env.c b/usr.bin/env/env.c
index 08aaa75c695..c1629759baa 100644
--- a/usr.bin/env/env.c
+++ b/usr.bin/env/env.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: env.c,v 1.17 2016/10/28 07:22:59 schwarze Exp $ */
+/* $OpenBSD: env.c,v 1.18 2024/07/28 10:08:44 kn Exp $ */
/*
* Copyright (c) 1988, 1993, 1994
@@ -49,13 +49,17 @@ main(int argc, char *argv[])
if (pledge("stdio exec", NULL) == -1)
err(1, "pledge");
- while ((ch = getopt(argc, argv, "i-")) != -1)
+ while ((ch = getopt(argc, argv, "-iu:")) != -1)
switch(ch) {
case '-': /* obsolete */
case 'i':
if ((environ = calloc(1, sizeof(char *))) == NULL)
err(126, "calloc");
break;
+ case 'u':
+ if (unsetenv(optarg) == -1)
+ err(126, "unsetenv");
+ break;
default:
usage();
}
@@ -91,7 +95,7 @@ usage(void)
{
extern char *__progname;
- (void)fprintf(stderr, "usage: %s [-i] [name=value ...] "
+ (void)fprintf(stderr, "usage: %s [-i] [-u name] [name=value ...] "
"[utility [argument ...]]\n", __progname);
exit(1);
}