Commit | Line | Data |
---|---|---|
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 |
9 | static 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 | |
c7411ed8 | 15 | static char sccsid[] = "@(#)env.c 8.1 (Berkeley) %G%"; |
30c455cf KB |
16 | #endif /* not lint */ |
17 | ||
18 | #include <stdio.h> | |
38dde0cd | 19 | #include <string.h> |
30c455cf KB |
20 | |
21 | main(argc, argv) | |
22 | int argc; | |
23 | char **argv; | |
24 | { | |
25 | extern char **environ; | |
26 | extern int errno, optind; | |
27 | register char **ep, *p; | |
28 | char *cleanenv[1]; | |
29 | int ch; | |
30 | ||
31 | while ((ch = getopt(argc, argv, "-")) != EOF) | |
32 | switch((char)ch) { | |
33 | case '-': | |
34 | environ = cleanenv; | |
35 | cleanenv[0] = NULL; | |
36 | break; | |
37 | case '?': | |
38 | default: | |
39 | (void)fprintf(stderr, | |
40 | "usage: env [-] [name=value ...] [command]\n"); | |
41 | exit(1); | |
42 | } | |
43 | for (argv += optind; *argv && (p = index(*argv, '=')); ++argv) | |
44 | (void)setenv(*argv, ++p, 1); | |
45 | if (*argv) { | |
46 | execvp(*argv, argv); | |
47 | (void)fprintf(stderr, "env: %s: %s\n", *argv, | |
48 | strerror(errno)); | |
49 | exit(1); | |
50 | } | |
51 | for (ep = environ; *ep; ep++) | |
52 | (void)printf("%s\n", *ep); | |
53 | exit(0); | |
54 | } |