Index: env.1 =================================================================== RCS file: /cvsroot/src/usr.bin/env/env.1,v retrieving revision 1.12 diff -u -r1.12 env.1 --- env.1 8 Jun 2007 18:20:42 -0000 1.12 +++ env.1 8 Feb 2020 10:21:01 -0000 @@ -32,7 +32,7 @@ .\" from: @(#)printenv.1 6.7 (Berkeley) 7/28/91 .\" $NetBSD: env.1,v 1.12 2007/06/08 18:20:42 wiz 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 Index: env.c =================================================================== RCS file: /cvsroot/src/usr.bin/env/env.c,v retrieving revision 1.20 diff -u -r1.20 env.c --- env.c 16 Nov 2010 02:53:49 -0000 1.20 +++ env.c 8 Feb 2020 10:21:01 -0000 @@ -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); }