? a.out Index: env.1 =================================================================== RCS file: /cvsroot/src/usr.bin/env/env.1,v retrieving revision 1.13 diff -u -r1.13 env.1 --- env.1 8 Feb 2020 10:30:22 -0000 1.13 +++ env.1 8 Feb 2020 10:57:03 -0000 @@ -40,7 +40,7 @@ .Nd set and print environment .Sh SYNOPSIS .Nm -.Op Fl i +.Op Fl 0i .Op Fl u Ar name .Op Ar name=value ... .Oo @@ -86,10 +86,17 @@ .Ar utility is specified, .Nm -prints out the names and values -of the variables in the environment, with one +prints out the names and values of the variables in the environment. +Each .Ar name=value -pair per line. +pair is separated by a new line unless +.Fl 0 +is specified, in which case name/value pairs are separated by NUL. +Both +.Fl 0 +and +.Ar utility +must not be specified together. .Sh EXIT STATUS .Nm exits with one of the following values: @@ -111,6 +118,11 @@ see its manual page for more information. In this case the exit code is returned by the utility itself, not .Nm . +.It 125 +.Ar utility +was specified together with the +.Fl 0 +option. .It 126 .Ar utility was found, but could not be invoked. @@ -125,7 +137,9 @@ .Pp The .Fl u -option is a non-standard extension. +and +.Fl 0 +options are non-standard extensions. .Sh SEE ALSO .Xr execvp 3 , .Xr environ 7 @@ -142,7 +156,9 @@ .Pp The .Fl u -option first appeared in +and +.Fl 0 +optionss first appeared in .Nx 10 . .Sh BUGS .Nm Index: env.c =================================================================== RCS file: /cvsroot/src/usr.bin/env/env.c,v retrieving revision 1.22 diff -u -r1.22 env.c --- env.c 8 Feb 2020 10:36:02 -0000 1.22 +++ env.c 8 Feb 2020 10:57:03 -0000 @@ -54,15 +54,19 @@ int main(int argc, char **argv) { - char **ep; + char **ep, term; char *cleanenv[1]; int ch; setprogname(*argv); (void)setlocale(LC_ALL, ""); - while ((ch = getopt(argc, argv, "-iu:")) != -1) + term = '\n'; + while ((ch = getopt(argc, argv, "-0iu:")) != -1) switch((char)ch) { + case '0': + term = '\0'; + break; case '-': /* obsolete */ case 'i': environ = cleanenv; @@ -82,7 +86,11 @@ if (*argv) { /* return 127 if the command to be run could not be found; 126 - if the command was found but could not be invoked */ + if the command was found but could not be invoked; 125 if + -0 was specified with utility.*/ + + if (term == '\0') + errx(125, "cannot specify command with -0"); (void)execvp(*argv, argv); err((errno == ENOENT) ? 127 : 126, "%s", *argv); @@ -90,7 +98,7 @@ } for (ep = environ; *ep; ep++) - (void)printf("%s\n", *ep); + (void)printf("%s%c", *ep, term); exit(0); } @@ -99,7 +107,7 @@ usage(void) { (void)fprintf(stderr, - "Usage: %s [-i] [-u name] [name=value ...] [command]\n", + "Usage: %s [-0i] [-u name] [name=value ...] [command]\n", getprogname()); exit(1); }