Commit | Line | Data |
---|---|---|
22e155fc | 1 | /* |
35901a68 KB |
2 | * Copyright (c) 1987 Regents of the University of California. |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms are permitted | |
6 | * provided that this notice is preserved and that due credit is given | |
7 | * to the University of California at Berkeley. The name of the University | |
8 | * may not be used to endorse or promote products derived from this | |
9 | * software without specific prior written permission. This software | |
10 | * is provided ``as is'' without express or implied warranty. | |
22e155fc DF |
11 | */ |
12 | ||
13 | #ifndef lint | |
14 | char copyright[] = | |
35901a68 | 15 | "@(#) Copyright (c) 1987 Regents of the University of California.\n\ |
22e155fc | 16 | All rights reserved.\n"; |
35901a68 | 17 | #endif /* not lint */ |
22e155fc DF |
18 | |
19 | #ifndef lint | |
35901a68 KB |
20 | static char sccsid[] = "@(#)printenv.c 5.2 (Berkeley) %G%"; |
21 | #endif /* not lint */ | |
22e155fc | 22 | |
18745775 BJ |
23 | /* |
24 | * printenv | |
25 | * | |
26 | * Bill Joy, UCB | |
27 | * February, 1979 | |
28 | */ | |
18745775 BJ |
29 | main(argc, argv) |
30 | int argc; | |
35901a68 | 31 | char **argv; |
18745775 | 32 | { |
35901a68 KB |
33 | extern char **environ; |
34 | register char *cp, **ep; | |
35 | register int len; | |
18745775 | 36 | |
35901a68 | 37 | if (argc < 2) { |
18745775 | 38 | for (ep = environ; *ep; ep++) |
35901a68 KB |
39 | puts(*ep); |
40 | exit(0); | |
41 | } | |
42 | len = strlen(*++argv); | |
43 | for (ep = environ; *ep; ep++) | |
44 | if (!strncmp(*ep, *argv, len)) { | |
45 | cp = *ep + len; | |
46 | if (!*cp || *cp == '=') { | |
47 | puts(*cp ? cp + 1 : cp); | |
48 | exit(0); | |
18745775 | 49 | } |
35901a68 KB |
50 | } |
51 | exit(1); | |
18745775 | 52 | } |