? .gdbinit ? a414225db16458baef6089e97fcf23c619ce21f9.patch ? env ? env.chdir.diff ? env.html1 Index: env.1 =================================================================== RCS file: /cvsroot/src/usr.bin/env/env.1,v retrieving revision 1.15 diff -u -p -r1.15 env.1 --- env.1 8 Feb 2020 11:10:08 -0000 1.15 +++ env.1 28 Oct 2024 09:48:10 -0000 @@ -32,7 +32,7 @@ .\" from: @(#)printenv.1 6.7 (Berkeley) 7/28/91 .\" $NetBSD: env.1,v 1.15 2020/02/08 11:10:08 leot Exp $ .\" -.Dd February 8, 2020 +.Dd October 28, 2024 .Dt ENV 1 .Os .Sh NAME @@ -41,6 +41,7 @@ .Sh SYNOPSIS .Nm .Op Fl 0i +.Op Fl C Ar dir .Op Fl u Ar name .Op Ar name=value ... .Oo @@ -53,23 +54,28 @@ executes .Ar utility after modifying the environment as specified on the command line. -The option +Each .Ar name=value -specifies +option specifies an environmental variable, .Ar name , with a value of .Ar value . -The option +The .Sq Fl i -causes +option causes .Nm to completely ignore the environment it inherits. .Pp -The option +The +.Sq Fl C Ar dir +option causes the working directory to be changed to +.Ar dir . +.Pp +The .Sq Fl u Ar name -causes removal of the +option causes removal of the .Ar name environment variable if it is in the environment. This is similar to the @@ -92,9 +98,9 @@ Each pair is separated by a new line unless .Fl 0 is specified, in which case name/value pairs are separated by NUL. -Both +The .Fl 0 -and +option and .Ar utility must not be specified together. .Sh EXIT STATUS @@ -136,11 +142,12 @@ The historic option has been deprecated but is still supported in this implementation. .Pp The -.Fl u +.Fl C , u and .Fl 0 options are non-standard extensions. .Sh SEE ALSO +.Xr chdir 2 , .Xr execvp 3 , .Xr environ 7 .Sh STANDARDS @@ -160,6 +167,11 @@ and .Fl 0 options first appeared in .Nx 10 . +.Pp +The +.Fl C +option first appeared in +.Nx 10.1 . .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.23 diff -u -p -r1.23 env.c --- env.c 8 Feb 2020 11:02:07 -0000 1.23 +++ env.c 28 Oct 2024 09:48:10 -0000 @@ -62,11 +62,15 @@ main(int argc, char **argv) (void)setlocale(LC_ALL, ""); term = '\n'; - while ((ch = getopt(argc, argv, "-0iu:")) != -1) + while ((ch = getopt(argc, argv, "-0C:iu:")) != -1) switch((char)ch) { case '0': term = '\0'; break; + case 'C': + if (chdir(optarg) == -1) + err(EXIT_FAILURE, "chdir '%s'", optarg); + break; case '-': /* obsolete */ case 'i': environ = cleanenv; @@ -74,7 +78,7 @@ main(int argc, char **argv) break; case 'u': if (unsetenv(optarg) == -1) - errx(EXIT_FAILURE, "unsetenv %s", optarg); + err(EXIT_FAILURE, "unsetenv '%s'", optarg); break; case '?': default: @@ -107,7 +111,7 @@ static void usage(void) { (void)fprintf(stderr, - "Usage: %s [-0i] [-u name] [name=value ...] [command]\n", + "Usage: %s [-0i] [-C dir] [-u name] [name=value ...] [command]\n", getprogname()); exit(1); }