"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Mike Frysinger | 6d1d2e5 | 2005-04-21 23:23:13 +0000 | [diff] [blame] | 2 | /* |
| 3 | * printenv implementation for busybox |
| 4 | * |
| 5 | * Copyright (C) 2005 by Erik Andersen <andersen@codepoet.org> |
| 6 | * Copyright (C) 2005 by Mike Frysinger <vapier@gentoo.org> |
| 7 | * |
"Robert P. J. Day" | 801ab14 | 2006-07-12 07:56:04 +0000 | [diff] [blame] | 8 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Mike Frysinger | 6d1d2e5 | 2005-04-21 23:23:13 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 11 | #include "libbb.h" |
Denis Vlasenko | 5b34083 | 2007-05-17 23:02:14 +0000 | [diff] [blame] | 12 | extern char **environ; |
Mike Frysinger | 6d1d2e5 | 2005-04-21 23:23:13 +0000 | [diff] [blame] | 13 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame^] | 14 | int printenv_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Mike Frysinger | 6d1d2e5 | 2005-04-21 23:23:13 +0000 | [diff] [blame] | 15 | int printenv_main(int argc, char **argv) |
| 16 | { |
Mike Frysinger | 6d1d2e5 | 2005-04-21 23:23:13 +0000 | [diff] [blame] | 17 | /* no variables specified, show whole env */ |
Denis Vlasenko | e013475 | 2007-08-06 02:55:41 +0000 | [diff] [blame] | 18 | if (argc == 1) { |
| 19 | int e = 0; |
Mike Frysinger | 6d1d2e5 | 2005-04-21 23:23:13 +0000 | [diff] [blame] | 20 | while (environ[e]) |
| 21 | puts(environ[e++]); |
Denis Vlasenko | e013475 | 2007-08-06 02:55:41 +0000 | [diff] [blame] | 22 | } else { |
| 23 | /* search for specified variables and print them out if found */ |
Mike Frysinger | 6d1d2e5 | 2005-04-21 23:23:13 +0000 | [diff] [blame] | 24 | char *arg, *env; |
| 25 | |
Denis Vlasenko | e013475 | 2007-08-06 02:55:41 +0000 | [diff] [blame] | 26 | while ((arg = *++argv) != NULL) { |
| 27 | env = getenv(arg); |
| 28 | if (env) |
| 29 | puts(env); |
| 30 | } |
Mike Frysinger | 6d1d2e5 | 2005-04-21 23:23:13 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Denis Vlasenko | f0ed376 | 2006-10-26 23:21:47 +0000 | [diff] [blame] | 33 | fflush_stdout_and_exit(0); |
Mike Frysinger | 6d1d2e5 | 2005-04-21 23:23:13 +0000 | [diff] [blame] | 34 | } |