Add a '-v' option to `env', to make it easier to discover exactly what steps
it is doing, and what order it does them. This will be much more useful as more options are added. Approved by: re (blanket `env')
This commit is contained in:
parent
ecc1960073
commit
f66e378b5e
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=147490
29
usr.bin/env/env.c
vendored
29
usr.bin/env/env.c
vendored
@ -55,29 +55,50 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
extern char **environ;
|
||||
|
||||
int env_verbosity;
|
||||
|
||||
static void usage(void);
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
char **ep, *p;
|
||||
char **ep, *p, **parg;
|
||||
char *cleanenv[1];
|
||||
int ch;
|
||||
|
||||
while ((ch = getopt(argc, argv, "-i")) != -1)
|
||||
while ((ch = getopt(argc, argv, "-iv")) != -1)
|
||||
switch(ch) {
|
||||
case '-':
|
||||
case 'i':
|
||||
environ = cleanenv;
|
||||
cleanenv[0] = NULL;
|
||||
if (env_verbosity)
|
||||
fprintf(stderr, "#env clearing environ\n");
|
||||
break;
|
||||
case 'v':
|
||||
env_verbosity++;
|
||||
if (env_verbosity > 1)
|
||||
fprintf(stderr, "#env verbosity now at %d\n",
|
||||
env_verbosity);
|
||||
break;
|
||||
case '?':
|
||||
default:
|
||||
usage();
|
||||
}
|
||||
for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv)
|
||||
for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv) {
|
||||
if (env_verbosity)
|
||||
fprintf(stderr, "#env setenv:\t%s\n", *argv);
|
||||
(void)setenv(*argv, ++p, 1);
|
||||
}
|
||||
if (*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);
|
||||
}
|
||||
@ -90,6 +111,6 @@ static void
|
||||
usage(void)
|
||||
{
|
||||
(void)fprintf(stderr,
|
||||
"usage: env [-i] [name=value ...] [utility [argument ...]]\n");
|
||||
"usage: env [-iv] [name=value ...] [utility [argument ...]]\n");
|
||||
exit(1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user