Index: coreutils/Makefile.in =================================================================== --- coreutils/Makefile.in (revision 10146) +++ coreutils/Makefile.in (revision 10147) @@ -60,6 +60,7 @@ COREUTILS-$(CONFIG_MV) += mv.o COREUTILS-$(CONFIG_NICE) += nice.o COREUTILS-$(CONFIG_OD) += od.o +COREUTILS-$(CONFIG_PRINTENV) += printenv.o COREUTILS-$(CONFIG_PRINTF) += printf.o COREUTILS-$(CONFIG_PWD) += pwd.o COREUTILS-$(CONFIG_REALPATH) += realpath.o Index: coreutils/printenv.c =================================================================== --- coreutils/printenv.c (revision 0) +++ coreutils/printenv.c (revision 10147) @@ -0,0 +1,52 @@ +/* + * printenv implementation for busybox + * + * Copyright (C) 2005 by Erik Andersen + * Copyright (C) 2005 by Mike Frysinger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include +#include +#include + +int printenv_main(int argc, char **argv) +{ + extern char **environ; + int e = 0; + + /* no variables specified, show whole env */ + if (argc == 1) + while (environ[e]) + puts(environ[e++]); + + /* search for specified variables and print them out if found */ + else { + int i; + size_t l; + char *arg, *env; + + for (i=1; (arg = argv[i]); ++i) + for (; (env = environ[e]); ++e) { + l = strlen(arg); + if (!strncmp(env, arg, l) && env[l] == '=') + puts(env + l + 1); + } + } + + exit(EXIT_SUCCESS); +} Index: coreutils/Config.in =================================================================== --- coreutils/Config.in (revision 10146) +++ coreutils/Config.in (revision 10147) @@ -164,6 +164,12 @@ a command; without options it displays the current environment. +config CONFIG_PRINTENV + bool "printenv" + default n + help + printenv is used to print all or part of environment. + config CONFIG_EXPR bool "expr" default n --- include/usage.h +++ include/usage.h @@ -1949,6 +1949,12 @@ "Options:\n" \ "\t-d\t\tdelay interval for shutting off." +#define printenv_trivial_usage \ + "[VARIABLES...]" +#define printenv_full_usage \ + "print all or part of environment\n\n" \ + "If no environment VARIABLE specified, print them all." + #define printf_trivial_usage \ "FORMAT [ARGUMENT...]" #define printf_full_usage \ --- include/applets.h +++ include/applets.h @@ -452,6 +452,9 @@ #ifdef CONFIG_POWEROFF APPLET(poweroff, poweroff_main, _BB_DIR_SBIN, _BB_SUID_NEVER) #endif +#ifdef CONFIG_PRINTENV + APPLET(printenv, printenv_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif #ifdef CONFIG_PRINTF APPLET(printf, printf_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) #endif