Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F151679135
D22230.id63917.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D22230.id63917.diff
View Options
Index: usr.bin/env/env.1
===================================================================
--- usr.bin/env/env.1
+++ usr.bin/env/env.1
@@ -31,7 +31,7 @@
.\" From FreeBSD: src/usr.bin/printenv/printenv.1,v 1.17 2002/11/26 17:33:35 ru Exp
.\" $FreeBSD$
.\"
-.Dd April 17, 2008
+.Dd November 3, 2019
.Dt ENV 1
.Os
.Sh NAME
@@ -39,7 +39,7 @@
.Nd set environment and execute command, or print environment
.Sh SYNOPSIS
.Nm
-.Op Fl iv
+.Op Fl 0iv
.Op Fl P Ar altpath
.Op Fl S Ar string
.Op Fl u Ar name
@@ -64,6 +64,8 @@
.Pp
The options are as follows:
.Bl -tag -width indent
+.It Fl 0
+End each output line with NUL, not newline.
.It Fl i
Execute the
.Ar utility
@@ -132,6 +134,11 @@
.Nm
prints out the names and values
of the variables in the environment, with one name/value pair per line.
+If
+.Fl 0
+is supplied,
+.Ar utility
+is ignored and the variables are separated by NUL instead of lines.
.\"
.Ss Details of Fl S \&Ss (split-string) processing
The processing of the
Index: usr.bin/env/env.c
===================================================================
--- usr.bin/env/env.c
+++ usr.bin/env/env.c
@@ -62,19 +62,23 @@
int
main(int argc, char **argv)
{
- char *altpath, **ep, *p, **parg;
+ char *altpath, **ep, *p, **parg, term;
char *cleanenv[1];
int ch, want_clear;
int rtrn;
altpath = NULL;
want_clear = 0;
- while ((ch = getopt(argc, argv, "-iP:S:u:v")) != -1)
+ term = '\n';
+ while ((ch = getopt(argc, argv, "-0iP:S:u:v")) != -1)
switch(ch) {
case '-':
case 'i':
want_clear = 1;
break;
+ case '0':
+ term = '\0';
+ break;
case 'P':
altpath = strdup(optarg);
break;
@@ -118,21 +122,25 @@
err(EXIT_FAILURE, "setenv %s", *argv);
}
if (*argv) {
- if (altpath)
- search_paths(altpath, argv);
- if (env_verbosity) {
- fprintf(stderr, "#env executing:\t%s\n", *argv);
- for (parg = argv, argc = 0; *parg; parg++, argc++)
- fprintf(stderr, "#env arg[%d]=\t'%s'\n",
- argc, *parg);
- if (env_verbosity > 1)
- sleep(1);
+ if (term == '\0')
+ fprintf(stderr, "Command ignored with -0.\n");
+ else {
+ if (altpath)
+ search_paths(altpath, argv);
+ if (env_verbosity) {
+ fprintf(stderr, "#env executing:\t%s\n", *argv);
+ for (parg = argv, argc = 0; *parg; parg++, argc++)
+ fprintf(stderr, "#env arg[%d]=\t'%s'\n",
+ argc, *parg);
+ if (env_verbosity > 1)
+ sleep(1);
+ }
+ execvp(*argv, argv);
+ err(errno == ENOENT ? 127 : 126, "%s", *argv);
}
- execvp(*argv, argv);
- err(errno == ENOENT ? 127 : 126, "%s", *argv);
}
for (ep = environ; *ep; ep++)
- (void)printf("%s\n", *ep);
+ (void)printf("%s%c", *ep, term);
exit(0);
}
@@ -140,7 +148,7 @@
usage(void)
{
(void)fprintf(stderr,
- "usage: env [-iv] [-P utilpath] [-S string] [-u name]\n"
+ "usage: env [-0iv] [-P utilpath] [-S string] [-u name]\n"
" [name=value ...] [utility [argument ...]]\n");
exit(1);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Apr 10, 11:28 PM (9 h, 50 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31253478
Default Alt Text
D22230.id63917.diff (2 KB)
Attached To
Mode
D22230: Add support for -0 to env(1)
Attached
Detach File
Event Timeline
Log In to Comment