Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/env Implement env(1) -u
details: https://anonhg.NetBSD.org/src/rev/5d3348c265e0
branches: trunk
changeset: 1007155:5d3348c265e0
user: kamil <kamil%NetBSD.org@localhost>
date: Sat Feb 08 10:30:22 2020 +0000
description:
Implement env(1) -u
The option '-u name' causes removal of the name environment variable if
it is in the environment. This is similar to the unset command in sh(1).
The value for name must not include the '=' character.
Add HISTORY section in the man page.
The -u argument is implemented by Linux, FreeBSD and Darwin.
The lack of -u in NetBSD is a cause for a frequent fallout in the LLVM
toolchain test-suite.
diffstat:
usr.bin/env/env.1 | 36 +++++++++++++++++++++++++++++++++---
usr.bin/env/env.c | 11 ++++++++---
2 files changed, 41 insertions(+), 6 deletions(-)
diffs (120 lines):
diff -r c5d3bf1a4662 -r 5d3348c265e0 usr.bin/env/env.1
--- a/usr.bin/env/env.1 Sat Feb 08 09:05:08 2020 +0000
+++ b/usr.bin/env/env.1 Sat Feb 08 10:30:22 2020 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: env.1,v 1.12 2007/06/08 18:20:42 wiz Exp $
+.\" $NetBSD: env.1,v 1.13 2020/02/08 10:30:22 kamil Exp $
.\"
.\" Copyright (c) 1980, 1990 The Regents of the University of California.
.\" All rights reserved.
@@ -30,9 +30,9 @@
.\" SUCH DAMAGE.
.\"
.\" from: @(#)printenv.1 6.7 (Berkeley) 7/28/91
-.\" $NetBSD: env.1,v 1.12 2007/06/08 18:20:42 wiz Exp $
+.\" $NetBSD: env.1,v 1.13 2020/02/08 10:30:22 kamil Exp $
.\"
-.Dd June 8, 2007
+.Dd February 8, 2020
.Dt ENV 1
.Os
.Sh NAME
@@ -41,6 +41,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl i
+.Op Fl u Ar name
.Op Ar name=value ...
.Oo
.Ar utility
@@ -66,6 +67,21 @@
to completely ignore the environment
it inherits.
.Pp
+The option
+.Sq Fl u Ar name
+causes removal of the
+.Ar name
+environment variable if it is in the environment.
+This is similar to the
+.Ic unset
+command in
+.Xr sh 1 .
+The value for
+.Ar name
+must not include the
+.Ql =
+character.
+.Pp
If no
.Ar utility
is specified,
@@ -106,6 +122,10 @@
The historic
.Fl
option has been deprecated but is still supported in this implementation.
+.Pp
+The
+.Fl u
+option is a non-standard extension.
.Sh SEE ALSO
.Xr execvp 3 ,
.Xr environ 7
@@ -114,6 +134,16 @@
.Nm
utility conforms to
.St -p1003.2-92 .
+.Sh HISTORY
+The
+.Nm
+command appeared in
+.Bx 4.4 .
+.Pp
+The
+.Fl u
+option first appeared in
+.Nx 10 .
.Sh BUGS
.Nm
doesn't handle commands with equal
diff -r c5d3bf1a4662 -r 5d3348c265e0 usr.bin/env/env.c
--- a/usr.bin/env/env.c Sat Feb 08 09:05:08 2020 +0000
+++ b/usr.bin/env/env.c Sat Feb 08 10:30:22 2020 +0000
@@ -35,7 +35,7 @@
#ifndef lint
/*static char sccsid[] = "@(#)env.c 8.3 (Berkeley) 4/2/94";*/
-__RCSID("$NetBSD: env.c,v 1.20 2010/11/16 02:53:49 christos Exp $");
+__RCSID("$NetBSD: env.c,v 1.21 2020/02/08 10:30:22 kamil Exp $");
#endif /* not lint */
#include <err.h>
@@ -60,13 +60,17 @@
setprogname(*argv);
(void)setlocale(LC_ALL, "");
- while ((ch = getopt(argc, argv, "-i")) != -1)
+ while ((ch = getopt(argc, argv, "-iu:")) != -1)
switch((char)ch) {
case '-': /* obsolete */
case 'i':
environ = cleanenv;
cleanenv[0] = NULL;
break;
+ case 'u':
+ if (unsetenv(optarg) == -1)
+ errx(EXIT_FAILURE, "unsetenv %s", optarg);
+ break;
case '?':
default:
usage();
@@ -93,7 +97,8 @@
static void
usage(void)
{
- (void)fprintf(stderr, "Usage: %s [-i] [name=value ...] [command]\n",
+ (void)fprintf(stderr,
+ "Usage: %s [-i] [-u name] [name=value ...] [command]\n",
getprogname());
exit(1);
}
Home |
Main Index |
Thread Index |
Old Index