From 82ebcba30a9758c7d78686445ec2eaf32d2f4481 Mon Sep 17 00:00:00 2001 From: gad Date: Mon, 20 Jun 2005 03:43:25 +0000 Subject: Add the '-S' and '-P' options. The '-S' option can be used to split apart a string, and supports some text substitutions. This can be used to provide all the flexibility (and more!) that was lost by recent changes to how the kernel parses #!-lines in shell scripts. The '-P' option provides a way to specify an alternate set of directories to use when searching for the 'utility' program to run. This way you can be sure what directories are used for that search, without changing the value of PATH that the user has set. Note that on FreeBSD 6.0, this option is worthless unless the '-S' option is also used. Approved by: re (blanket `env') --- usr.bin/env/env.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'usr.bin/env/env.c') diff --git a/usr.bin/env/env.c b/usr.bin/env/env.c index a7eb536..56c671b 100644 --- a/usr.bin/env/env.c +++ b/usr.bin/env/env.c @@ -53,6 +53,8 @@ __FBSDID("$FreeBSD$"); #include #include +#include "envopts.h" + extern char **environ; int env_verbosity; @@ -62,17 +64,28 @@ static void usage(void); int main(int argc, char **argv) { - char **ep, *p, **parg; + char *altpath, **ep, *p, **parg; char *cleanenv[1]; int ch, want_clear; + altpath = NULL; want_clear = 0; - while ((ch = getopt(argc, argv, "-iv")) != -1) + while ((ch = getopt(argc, argv, "-iP:S:v")) != -1) switch(ch) { case '-': case 'i': want_clear = 1; break; + case 'P': + altpath = strdup(optarg); + break; + case 'S': + /* + * The -S option, for "split string on spaces, with + * support for some simple substitutions"... + */ + split_spaces(optarg, &optind, &argc, &argv); + break; case 'v': env_verbosity++; if (env_verbosity > 1) @@ -96,6 +109,8 @@ main(int argc, char **argv) (void)setenv(*argv, ++p, 1); } 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++) @@ -116,6 +131,7 @@ static void usage(void) { (void)fprintf(stderr, - "usage: env [-iv] [name=value ...] [utility [argument ...]]\n"); + "usage: env [-iv] [-P utilpath] [-S string] [name=value ...]" + " [utility [argument ...]]\n"); exit(1); } -- cgit v1.1