prettyness police
[unix-history] / usr / src / usr.bin / env / env.c
CommitLineData
30c455cf 1/*
c7411ed8
KB
2 * Copyright (c) 1988, 1993
3 * The Regents of the University of California. All rights reserved.
30c455cf 4 *
f15db449 5 * %sccs.include.redist.c%
30c455cf
KB
6 */
7
8#ifndef lint
c7411ed8
KB
9static char copyright[] =
10"@(#) Copyright (c) 1988, 1993\n\
11 The Regents of the University of California. All rights reserved.\n";
30c455cf
KB
12#endif /* not lint */
13
14#ifndef lint
d3acad8d 15static char sccsid[] = "@(#)env.c 8.2 (Berkeley) %G%";
30c455cf
KB
16#endif /* not lint */
17
d3acad8d 18#include <err.h>
30c455cf 19#include <stdio.h>
38dde0cd 20#include <string.h>
d3acad8d
JSP
21#include <stdlib.h>
22#include <unistd.h>
30c455cf 23
d3acad8d
JSP
24extern char **environ;
25
26int
30c455cf
KB
27main(argc, argv)
28 int argc;
29 char **argv;
30{
d3acad8d 31 char **ep, *p;
30c455cf
KB
32 char *cleanenv[1];
33 int ch;
34
35 while ((ch = getopt(argc, argv, "-")) != EOF)
d3acad8d 36 switch(ch) {
30c455cf
KB
37 case '-':
38 environ = cleanenv;
39 cleanenv[0] = NULL;
40 break;
41 case '?':
42 default:
43 (void)fprintf(stderr,
44 "usage: env [-] [name=value ...] [command]\n");
45 exit(1);
46 }
d3acad8d 47 for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv)
30c455cf
KB
48 (void)setenv(*argv, ++p, 1);
49 if (*argv) {
50 execvp(*argv, argv);
d3acad8d 51 err(1, "%s", *argv);
30c455cf
KB
52 }
53 for (ep = environ; *ep; ep++)
54 (void)printf("%s\n", *ep);
55 exit(0);
56}