summaryrefslogtreecommitdiffstats
path: root/usr.bin/env/env.c
diff options
context:
space:
mode:
authorgad <gad@FreeBSD.org>2005-06-20 03:43:25 +0000
committergad <gad@FreeBSD.org>2005-06-20 03:43:25 +0000
commit82ebcba30a9758c7d78686445ec2eaf32d2f4481 (patch)
tree3fc7c846fa2293810c4c2f91e4161ef12ce38915 /usr.bin/env/env.c
parentb785b6343ef380b2072604d84d7dacc05e51a7c6 (diff)
downloadFreeBSD-src-82ebcba30a9758c7d78686445ec2eaf32d2f4481.zip
FreeBSD-src-82ebcba30a9758c7d78686445ec2eaf32d2f4481.tar.gz
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')
Diffstat (limited to 'usr.bin/env/env.c')
-rw-r--r--usr.bin/env/env.c22
1 files changed, 19 insertions, 3 deletions
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 <stdlib.h>
#include <unistd.h>
+#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);
}
OpenPOWER on IntegriCloud