diff options
| author | Eric Andersen <andersen@codepoet.org> | 2001-03-29 22:48:33 +0000 |
|---|---|---|
| committer | Eric Andersen <andersen@codepoet.org> | 2001-03-29 22:48:33 +0000 |
| commit | 84e229cfbe00d27ce81dad66c982bec0d50cdfd7 (patch) | |
| tree | 3b13416dae3293c97fdb0a66309bfa79e40cafcd | |
| parent | e5c24dfd010732ab6b80a96ad2a5414499c496c0 (diff) | |
| download | busybox-w32-84e229cfbe00d27ce81dad66c982bec0d50cdfd7.tar.gz busybox-w32-84e229cfbe00d27ce81dad66c982bec0d50cdfd7.tar.bz2 busybox-w32-84e229cfbe00d27ce81dad66c982bec0d50cdfd7.zip | |
Add in a new standalone env applet for fixing up app's environments
-Erik
| -rw-r--r-- | Changelog | 9 | ||||
| -rw-r--r-- | Config.h | 1 | ||||
| -rw-r--r-- | applets.h | 3 | ||||
| -rw-r--r-- | applets/usage.h | 9 | ||||
| -rw-r--r-- | coreutils/env.c | 97 | ||||
| -rw-r--r-- | env.c | 97 | ||||
| -rw-r--r-- | include/applets.h | 3 | ||||
| -rw-r--r-- | include/usage.h | 9 | ||||
| -rw-r--r-- | lash.c | 21 | ||||
| -rw-r--r-- | sh.c | 21 | ||||
| -rw-r--r-- | shell/lash.c | 21 | ||||
| -rw-r--r-- | usage.h | 9 |
12 files changed, 252 insertions, 48 deletions
| @@ -1,3 +1,12 @@ | |||
| 1 | 0.51pre | ||
| 2 | * Erik Andersen -- added env applet | ||
| 3 | * Erik Andersen -- Split utility.c into libbb | ||
| 4 | * <fixme> | ||
| 5 | |||
| 6 | |||
| 7 | -Erik Andersen, not yet released | ||
| 8 | |||
| 9 | |||
| 1 | 0.50 | 10 | 0.50 |
| 2 | * Erik Andersen -- added ifconfig interface status reporting | 11 | * Erik Andersen -- added ifconfig interface status reporting |
| 3 | * Erik Andersen -- Debian packaging updates | 12 | * Erik Andersen -- Debian packaging updates |
| @@ -32,6 +32,7 @@ | |||
| 32 | #define BB_DU | 32 | #define BB_DU |
| 33 | //#define BB_DUMPKMAP | 33 | //#define BB_DUMPKMAP |
| 34 | #define BB_ECHO | 34 | #define BB_ECHO |
| 35 | #define BB_ENV | ||
| 35 | //#define BB_EXPR | 36 | //#define BB_EXPR |
| 36 | //#define BB_FBSET | 37 | //#define BB_FBSET |
| 37 | //#define BB_FDFLUSH | 38 | //#define BB_FDFLUSH |
| @@ -131,6 +131,9 @@ | |||
| 131 | #if defined(BB_FEATURE_GREP_EGREP_ALIAS) && defined(BB_GREP) | 131 | #if defined(BB_FEATURE_GREP_EGREP_ALIAS) && defined(BB_GREP) |
| 132 | APPLET_NOUSAGE("egrep", grep_main, _BB_DIR_BIN) | 132 | APPLET_NOUSAGE("egrep", grep_main, _BB_DIR_BIN) |
| 133 | #endif | 133 | #endif |
| 134 | #ifdef BB_ENV | ||
| 135 | APPLET(env, env_main, _BB_DIR_USR_BIN) | ||
| 136 | #endif | ||
| 134 | #ifdef BB_EXPR | 137 | #ifdef BB_EXPR |
| 135 | APPLET(expr, expr_main, _BB_DIR_USR_BIN) | 138 | APPLET(expr, expr_main, _BB_DIR_USR_BIN) |
| 136 | #endif | 139 | #endif |
diff --git a/applets/usage.h b/applets/usage.h index dde3dd146..32b34e45f 100644 --- a/applets/usage.h +++ b/applets/usage.h | |||
| @@ -343,6 +343,15 @@ | |||
| 343 | "$ echo "Erik\nis\ncool"\n" \ | 343 | "$ echo "Erik\nis\ncool"\n" \ |
| 344 | "Erik\nis\ncool\n" | 344 | "Erik\nis\ncool\n" |
| 345 | 345 | ||
| 346 | #define env_trivial_usage \ | ||
| 347 | "[-] [-iu] [name=value ...] [command]" | ||
| 348 | #define env_full_usage \ | ||
| 349 | "Prints the current environment or runs a program after setting\n" \ | ||
| 350 | "up the specified environment.\n\n" \ | ||
| 351 | "Options:\n" \ | ||
| 352 | "\t-, -i\tstart with an empty environment\n" \ | ||
| 353 | "\t-u\tremove variable from the environment\n" | ||
| 354 | |||
| 346 | #define expr_trivial_usage \ | 355 | #define expr_trivial_usage \ |
| 347 | "EXPRESSION" | 356 | "EXPRESSION" |
| 348 | #define expr_full_usage \ | 357 | #define expr_full_usage \ |
diff --git a/coreutils/env.c b/coreutils/env.c new file mode 100644 index 000000000..56577b611 --- /dev/null +++ b/coreutils/env.c | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * env implementation for busybox | ||
| 4 | * | ||
| 5 | * Copyright (c) 1988, 1993, 1994 | ||
| 6 | * The Regents of the University of California. All rights reserved. | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU General Public License as published by | ||
| 10 | * the Free Software Foundation; either version 2 of the License, or | ||
| 11 | * (at your option) any later version. | ||
| 12 | * | ||
| 13 | * This program is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU General Public License | ||
| 19 | * along with this program; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 21 | * | ||
| 22 | * Original copyright notice is retained at the end of this file. | ||
| 23 | * | ||
| 24 | * Modified for BusyBox by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> | ||
| 25 | */ | ||
| 26 | |||
| 27 | #include <stdio.h> | ||
| 28 | #include <string.h> | ||
| 29 | #include <getopt.h> | ||
| 30 | #include <stdlib.h> | ||
| 31 | #include <unistd.h> | ||
| 32 | #include "busybox.h" | ||
| 33 | |||
| 34 | extern int env_main(int argc, char** argv) | ||
| 35 | { | ||
| 36 | char **ep, *p; | ||
| 37 | char *cleanenv[1]; | ||
| 38 | int ch; | ||
| 39 | |||
| 40 | while ((ch = getopt(argc, argv, "-iu:")) != -1) | ||
| 41 | switch(ch) { | ||
| 42 | case '-': | ||
| 43 | case 'i': | ||
| 44 | environ = cleanenv; | ||
| 45 | cleanenv[0] = NULL; | ||
| 46 | break; | ||
| 47 | case 'u': | ||
| 48 | unsetenv(optarg); | ||
| 49 | break; | ||
| 50 | default: | ||
| 51 | show_usage(); | ||
| 52 | } | ||
| 53 | for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv) | ||
| 54 | setenv(*argv, ++p, 1); | ||
| 55 | if (*argv) { | ||
| 56 | execvp(*argv, argv); | ||
| 57 | perror_msg_and_die("%s", *argv); | ||
| 58 | } | ||
| 59 | for (ep = environ; *ep; ep++) | ||
| 60 | printf("%s\n", *ep); | ||
| 61 | exit(EXIT_SUCCESS); | ||
| 62 | } | ||
| 63 | |||
| 64 | /* | ||
| 65 | * Copyright (c) 1988, 1993, 1994 | ||
| 66 | * The Regents of the University of California. All rights reserved. | ||
| 67 | * | ||
| 68 | * Redistribution and use in source and binary forms, with or without | ||
| 69 | * modification, are permitted provided that the following conditions | ||
| 70 | * are met: | ||
| 71 | * 1. Redistributions of source code must retain the above copyright | ||
| 72 | * notice, this list of conditions and the following disclaimer. | ||
| 73 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 74 | * notice, this list of conditions and the following disclaimer in the | ||
| 75 | * documentation and/or other materials provided with the distribution. | ||
| 76 | * | ||
| 77 | * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change | ||
| 78 | * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change> | ||
| 79 | * | ||
| 80 | * 4. Neither the name of the University nor the names of its contributors | ||
| 81 | * may be used to endorse or promote products derived from this software | ||
| 82 | * without specific prior written permission. | ||
| 83 | * | ||
| 84 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 85 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 86 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 87 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 88 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 89 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 90 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 91 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 92 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 93 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 94 | * SUCH DAMAGE. | ||
| 95 | */ | ||
| 96 | |||
| 97 | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * env implementation for busybox | ||
| 4 | * | ||
| 5 | * Copyright (c) 1988, 1993, 1994 | ||
| 6 | * The Regents of the University of California. All rights reserved. | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify | ||
| 9 | * it under the terms of the GNU General Public License as published by | ||
| 10 | * the Free Software Foundation; either version 2 of the License, or | ||
| 11 | * (at your option) any later version. | ||
| 12 | * | ||
| 13 | * This program is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU General Public License | ||
| 19 | * along with this program; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 21 | * | ||
| 22 | * Original copyright notice is retained at the end of this file. | ||
| 23 | * | ||
| 24 | * Modified for BusyBox by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> | ||
| 25 | */ | ||
| 26 | |||
| 27 | #include <stdio.h> | ||
| 28 | #include <string.h> | ||
| 29 | #include <getopt.h> | ||
| 30 | #include <stdlib.h> | ||
| 31 | #include <unistd.h> | ||
| 32 | #include "busybox.h" | ||
| 33 | |||
| 34 | extern int env_main(int argc, char** argv) | ||
| 35 | { | ||
| 36 | char **ep, *p; | ||
| 37 | char *cleanenv[1]; | ||
| 38 | int ch; | ||
| 39 | |||
| 40 | while ((ch = getopt(argc, argv, "-iu:")) != -1) | ||
| 41 | switch(ch) { | ||
| 42 | case '-': | ||
| 43 | case 'i': | ||
| 44 | environ = cleanenv; | ||
| 45 | cleanenv[0] = NULL; | ||
| 46 | break; | ||
| 47 | case 'u': | ||
| 48 | unsetenv(optarg); | ||
| 49 | break; | ||
| 50 | default: | ||
| 51 | show_usage(); | ||
| 52 | } | ||
| 53 | for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv) | ||
| 54 | setenv(*argv, ++p, 1); | ||
| 55 | if (*argv) { | ||
| 56 | execvp(*argv, argv); | ||
| 57 | perror_msg_and_die("%s", *argv); | ||
| 58 | } | ||
| 59 | for (ep = environ; *ep; ep++) | ||
| 60 | printf("%s\n", *ep); | ||
| 61 | exit(EXIT_SUCCESS); | ||
| 62 | } | ||
| 63 | |||
| 64 | /* | ||
| 65 | * Copyright (c) 1988, 1993, 1994 | ||
| 66 | * The Regents of the University of California. All rights reserved. | ||
| 67 | * | ||
| 68 | * Redistribution and use in source and binary forms, with or without | ||
| 69 | * modification, are permitted provided that the following conditions | ||
| 70 | * are met: | ||
| 71 | * 1. Redistributions of source code must retain the above copyright | ||
| 72 | * notice, this list of conditions and the following disclaimer. | ||
| 73 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 74 | * notice, this list of conditions and the following disclaimer in the | ||
| 75 | * documentation and/or other materials provided with the distribution. | ||
| 76 | * | ||
| 77 | * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change | ||
| 78 | * ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change> | ||
| 79 | * | ||
| 80 | * 4. Neither the name of the University nor the names of its contributors | ||
| 81 | * may be used to endorse or promote products derived from this software | ||
| 82 | * without specific prior written permission. | ||
| 83 | * | ||
| 84 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 85 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 86 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 87 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 88 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 89 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 90 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 91 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 92 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 93 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 94 | * SUCH DAMAGE. | ||
| 95 | */ | ||
| 96 | |||
| 97 | |||
diff --git a/include/applets.h b/include/applets.h index 0ab296312..255bd6b44 100644 --- a/include/applets.h +++ b/include/applets.h | |||
| @@ -131,6 +131,9 @@ | |||
| 131 | #if defined(BB_FEATURE_GREP_EGREP_ALIAS) && defined(BB_GREP) | 131 | #if defined(BB_FEATURE_GREP_EGREP_ALIAS) && defined(BB_GREP) |
| 132 | APPLET_NOUSAGE("egrep", grep_main, _BB_DIR_BIN) | 132 | APPLET_NOUSAGE("egrep", grep_main, _BB_DIR_BIN) |
| 133 | #endif | 133 | #endif |
| 134 | #ifdef BB_ENV | ||
| 135 | APPLET(env, env_main, _BB_DIR_USR_BIN) | ||
| 136 | #endif | ||
| 134 | #ifdef BB_EXPR | 137 | #ifdef BB_EXPR |
| 135 | APPLET(expr, expr_main, _BB_DIR_USR_BIN) | 138 | APPLET(expr, expr_main, _BB_DIR_USR_BIN) |
| 136 | #endif | 139 | #endif |
diff --git a/include/usage.h b/include/usage.h index dde3dd146..32b34e45f 100644 --- a/include/usage.h +++ b/include/usage.h | |||
| @@ -343,6 +343,15 @@ | |||
| 343 | "$ echo "Erik\nis\ncool"\n" \ | 343 | "$ echo "Erik\nis\ncool"\n" \ |
| 344 | "Erik\nis\ncool\n" | 344 | "Erik\nis\ncool\n" |
| 345 | 345 | ||
| 346 | #define env_trivial_usage \ | ||
| 347 | "[-] [-iu] [name=value ...] [command]" | ||
| 348 | #define env_full_usage \ | ||
| 349 | "Prints the current environment or runs a program after setting\n" \ | ||
| 350 | "up the specified environment.\n\n" \ | ||
| 351 | "Options:\n" \ | ||
| 352 | "\t-, -i\tstart with an empty environment\n" \ | ||
| 353 | "\t-u\tremove variable from the environment\n" | ||
| 354 | |||
| 346 | #define expr_trivial_usage \ | 355 | #define expr_trivial_usage \ |
| 347 | "EXPRESSION" | 356 | "EXPRESSION" |
| 348 | #define expr_full_usage \ | 357 | #define expr_full_usage \ |
| @@ -143,7 +143,6 @@ struct close_me { | |||
| 143 | 143 | ||
| 144 | /* function prototypes for builtins */ | 144 | /* function prototypes for builtins */ |
| 145 | static int builtin_cd(struct child_prog *cmd); | 145 | static int builtin_cd(struct child_prog *cmd); |
| 146 | static int builtin_env(struct child_prog *dummy); | ||
| 147 | static int builtin_exec(struct child_prog *cmd); | 146 | static int builtin_exec(struct child_prog *cmd); |
| 148 | static int builtin_exit(struct child_prog *cmd); | 147 | static int builtin_exit(struct child_prog *cmd); |
| 149 | static int builtin_fg_bg(struct child_prog *cmd); | 148 | static int builtin_fg_bg(struct child_prog *cmd); |
| @@ -203,7 +202,6 @@ static struct built_in_command bltins[] = { | |||
| 203 | /* Table of forking built-in functions (things that fork cannot change global | 202 | /* Table of forking built-in functions (things that fork cannot change global |
| 204 | * variables in the parent process, such as the current working directory) */ | 203 | * variables in the parent process, such as the current working directory) */ |
| 205 | static struct built_in_command bltins_forking[] = { | 204 | static struct built_in_command bltins_forking[] = { |
| 206 | {"env", "Print all environment variables", builtin_env}, | ||
| 207 | {"pwd", "Print current directory", builtin_pwd}, | 205 | {"pwd", "Print current directory", builtin_pwd}, |
| 208 | {"help", "List shell built-in commands", builtin_help}, | 206 | {"help", "List shell built-in commands", builtin_help}, |
| 209 | {NULL, NULL, NULL} | 207 | {NULL, NULL, NULL} |
| @@ -256,14 +254,13 @@ static inline void debug_printf(const char *format, ...) { } | |||
| 256 | builtin previous use notes | 254 | builtin previous use notes |
| 257 | ------ ----------------- --------- | 255 | ------ ----------------- --------- |
| 258 | cd cmd->progs[0] | 256 | cd cmd->progs[0] |
| 259 | env 0 | ||
| 260 | exec cmd->progs[0] squashed bug: didn't look for applets or forking builtins | 257 | exec cmd->progs[0] squashed bug: didn't look for applets or forking builtins |
| 261 | exit cmd->progs[0] | 258 | exit cmd->progs[0] |
| 262 | fg_bg cmd->progs[0], job_list->head, job_list->fg | 259 | fg_bg cmd->progs[0], job_list->head, job_list->fg |
| 263 | help 0 | 260 | help 0 |
| 264 | jobs job_list->head | 261 | jobs job_list->head |
| 265 | pwd 0 | 262 | pwd 0 |
| 266 | export cmd->progs[0] passes cmd, job_list to builtin_env(), which ignores them | 263 | export cmd->progs[0] |
| 267 | source cmd->progs[0] | 264 | source cmd->progs[0] |
| 268 | unset cmd->progs[0] | 265 | unset cmd->progs[0] |
| 269 | read cmd->progs[0] | 266 | read cmd->progs[0] |
| @@ -302,17 +299,6 @@ static int builtin_cd(struct child_prog *child) | |||
| 302 | return EXIT_SUCCESS; | 299 | return EXIT_SUCCESS; |
| 303 | } | 300 | } |
| 304 | 301 | ||
| 305 | /* built-in 'env' handler */ | ||
| 306 | static int builtin_env(struct child_prog *dummy) | ||
| 307 | { | ||
| 308 | char **e; | ||
| 309 | |||
| 310 | for (e = environ; *e; e++) { | ||
| 311 | printf( "%s\n", *e); | ||
| 312 | } | ||
| 313 | return (0); | ||
| 314 | } | ||
| 315 | |||
| 316 | /* built-in 'exec' handler */ | 302 | /* built-in 'exec' handler */ |
| 317 | static int builtin_exec(struct child_prog *child) | 303 | static int builtin_exec(struct child_prog *child) |
| 318 | { | 304 | { |
| @@ -436,7 +422,10 @@ static int builtin_export(struct child_prog *child) | |||
| 436 | char *v = child->argv[1]; | 422 | char *v = child->argv[1]; |
| 437 | 423 | ||
| 438 | if (v == NULL) { | 424 | if (v == NULL) { |
| 439 | return (builtin_env(child)); | 425 | char **e; |
| 426 | for (e = environ; *e; e++) { | ||
| 427 | printf( "%s\n", *e); | ||
| 428 | } | ||
| 440 | } | 429 | } |
| 441 | res = putenv(v); | 430 | res = putenv(v); |
| 442 | if (res) | 431 | if (res) |
| @@ -143,7 +143,6 @@ struct close_me { | |||
| 143 | 143 | ||
| 144 | /* function prototypes for builtins */ | 144 | /* function prototypes for builtins */ |
| 145 | static int builtin_cd(struct child_prog *cmd); | 145 | static int builtin_cd(struct child_prog *cmd); |
| 146 | static int builtin_env(struct child_prog *dummy); | ||
| 147 | static int builtin_exec(struct child_prog *cmd); | 146 | static int builtin_exec(struct child_prog *cmd); |
| 148 | static int builtin_exit(struct child_prog *cmd); | 147 | static int builtin_exit(struct child_prog *cmd); |
| 149 | static int builtin_fg_bg(struct child_prog *cmd); | 148 | static int builtin_fg_bg(struct child_prog *cmd); |
| @@ -203,7 +202,6 @@ static struct built_in_command bltins[] = { | |||
| 203 | /* Table of forking built-in functions (things that fork cannot change global | 202 | /* Table of forking built-in functions (things that fork cannot change global |
| 204 | * variables in the parent process, such as the current working directory) */ | 203 | * variables in the parent process, such as the current working directory) */ |
| 205 | static struct built_in_command bltins_forking[] = { | 204 | static struct built_in_command bltins_forking[] = { |
| 206 | {"env", "Print all environment variables", builtin_env}, | ||
| 207 | {"pwd", "Print current directory", builtin_pwd}, | 205 | {"pwd", "Print current directory", builtin_pwd}, |
| 208 | {"help", "List shell built-in commands", builtin_help}, | 206 | {"help", "List shell built-in commands", builtin_help}, |
| 209 | {NULL, NULL, NULL} | 207 | {NULL, NULL, NULL} |
| @@ -256,14 +254,13 @@ static inline void debug_printf(const char *format, ...) { } | |||
| 256 | builtin previous use notes | 254 | builtin previous use notes |
| 257 | ------ ----------------- --------- | 255 | ------ ----------------- --------- |
| 258 | cd cmd->progs[0] | 256 | cd cmd->progs[0] |
| 259 | env 0 | ||
| 260 | exec cmd->progs[0] squashed bug: didn't look for applets or forking builtins | 257 | exec cmd->progs[0] squashed bug: didn't look for applets or forking builtins |
| 261 | exit cmd->progs[0] | 258 | exit cmd->progs[0] |
| 262 | fg_bg cmd->progs[0], job_list->head, job_list->fg | 259 | fg_bg cmd->progs[0], job_list->head, job_list->fg |
| 263 | help 0 | 260 | help 0 |
| 264 | jobs job_list->head | 261 | jobs job_list->head |
| 265 | pwd 0 | 262 | pwd 0 |
| 266 | export cmd->progs[0] passes cmd, job_list to builtin_env(), which ignores them | 263 | export cmd->progs[0] |
| 267 | source cmd->progs[0] | 264 | source cmd->progs[0] |
| 268 | unset cmd->progs[0] | 265 | unset cmd->progs[0] |
| 269 | read cmd->progs[0] | 266 | read cmd->progs[0] |
| @@ -302,17 +299,6 @@ static int builtin_cd(struct child_prog *child) | |||
| 302 | return EXIT_SUCCESS; | 299 | return EXIT_SUCCESS; |
| 303 | } | 300 | } |
| 304 | 301 | ||
| 305 | /* built-in 'env' handler */ | ||
| 306 | static int builtin_env(struct child_prog *dummy) | ||
| 307 | { | ||
| 308 | char **e; | ||
| 309 | |||
| 310 | for (e = environ; *e; e++) { | ||
| 311 | printf( "%s\n", *e); | ||
| 312 | } | ||
| 313 | return (0); | ||
| 314 | } | ||
| 315 | |||
| 316 | /* built-in 'exec' handler */ | 302 | /* built-in 'exec' handler */ |
| 317 | static int builtin_exec(struct child_prog *child) | 303 | static int builtin_exec(struct child_prog *child) |
| 318 | { | 304 | { |
| @@ -436,7 +422,10 @@ static int builtin_export(struct child_prog *child) | |||
| 436 | char *v = child->argv[1]; | 422 | char *v = child->argv[1]; |
| 437 | 423 | ||
| 438 | if (v == NULL) { | 424 | if (v == NULL) { |
| 439 | return (builtin_env(child)); | 425 | char **e; |
| 426 | for (e = environ; *e; e++) { | ||
| 427 | printf( "%s\n", *e); | ||
| 428 | } | ||
| 440 | } | 429 | } |
| 441 | res = putenv(v); | 430 | res = putenv(v); |
| 442 | if (res) | 431 | if (res) |
diff --git a/shell/lash.c b/shell/lash.c index 22c56d444..28015cbb3 100644 --- a/shell/lash.c +++ b/shell/lash.c | |||
| @@ -143,7 +143,6 @@ struct close_me { | |||
| 143 | 143 | ||
| 144 | /* function prototypes for builtins */ | 144 | /* function prototypes for builtins */ |
| 145 | static int builtin_cd(struct child_prog *cmd); | 145 | static int builtin_cd(struct child_prog *cmd); |
| 146 | static int builtin_env(struct child_prog *dummy); | ||
| 147 | static int builtin_exec(struct child_prog *cmd); | 146 | static int builtin_exec(struct child_prog *cmd); |
| 148 | static int builtin_exit(struct child_prog *cmd); | 147 | static int builtin_exit(struct child_prog *cmd); |
| 149 | static int builtin_fg_bg(struct child_prog *cmd); | 148 | static int builtin_fg_bg(struct child_prog *cmd); |
| @@ -203,7 +202,6 @@ static struct built_in_command bltins[] = { | |||
| 203 | /* Table of forking built-in functions (things that fork cannot change global | 202 | /* Table of forking built-in functions (things that fork cannot change global |
| 204 | * variables in the parent process, such as the current working directory) */ | 203 | * variables in the parent process, such as the current working directory) */ |
| 205 | static struct built_in_command bltins_forking[] = { | 204 | static struct built_in_command bltins_forking[] = { |
| 206 | {"env", "Print all environment variables", builtin_env}, | ||
| 207 | {"pwd", "Print current directory", builtin_pwd}, | 205 | {"pwd", "Print current directory", builtin_pwd}, |
| 208 | {"help", "List shell built-in commands", builtin_help}, | 206 | {"help", "List shell built-in commands", builtin_help}, |
| 209 | {NULL, NULL, NULL} | 207 | {NULL, NULL, NULL} |
| @@ -256,14 +254,13 @@ static inline void debug_printf(const char *format, ...) { } | |||
| 256 | builtin previous use notes | 254 | builtin previous use notes |
| 257 | ------ ----------------- --------- | 255 | ------ ----------------- --------- |
| 258 | cd cmd->progs[0] | 256 | cd cmd->progs[0] |
| 259 | env 0 | ||
| 260 | exec cmd->progs[0] squashed bug: didn't look for applets or forking builtins | 257 | exec cmd->progs[0] squashed bug: didn't look for applets or forking builtins |
| 261 | exit cmd->progs[0] | 258 | exit cmd->progs[0] |
| 262 | fg_bg cmd->progs[0], job_list->head, job_list->fg | 259 | fg_bg cmd->progs[0], job_list->head, job_list->fg |
| 263 | help 0 | 260 | help 0 |
| 264 | jobs job_list->head | 261 | jobs job_list->head |
| 265 | pwd 0 | 262 | pwd 0 |
| 266 | export cmd->progs[0] passes cmd, job_list to builtin_env(), which ignores them | 263 | export cmd->progs[0] |
| 267 | source cmd->progs[0] | 264 | source cmd->progs[0] |
| 268 | unset cmd->progs[0] | 265 | unset cmd->progs[0] |
| 269 | read cmd->progs[0] | 266 | read cmd->progs[0] |
| @@ -302,17 +299,6 @@ static int builtin_cd(struct child_prog *child) | |||
| 302 | return EXIT_SUCCESS; | 299 | return EXIT_SUCCESS; |
| 303 | } | 300 | } |
| 304 | 301 | ||
| 305 | /* built-in 'env' handler */ | ||
| 306 | static int builtin_env(struct child_prog *dummy) | ||
| 307 | { | ||
| 308 | char **e; | ||
| 309 | |||
| 310 | for (e = environ; *e; e++) { | ||
| 311 | printf( "%s\n", *e); | ||
| 312 | } | ||
| 313 | return (0); | ||
| 314 | } | ||
| 315 | |||
| 316 | /* built-in 'exec' handler */ | 302 | /* built-in 'exec' handler */ |
| 317 | static int builtin_exec(struct child_prog *child) | 303 | static int builtin_exec(struct child_prog *child) |
| 318 | { | 304 | { |
| @@ -436,7 +422,10 @@ static int builtin_export(struct child_prog *child) | |||
| 436 | char *v = child->argv[1]; | 422 | char *v = child->argv[1]; |
| 437 | 423 | ||
| 438 | if (v == NULL) { | 424 | if (v == NULL) { |
| 439 | return (builtin_env(child)); | 425 | char **e; |
| 426 | for (e = environ; *e; e++) { | ||
| 427 | printf( "%s\n", *e); | ||
| 428 | } | ||
| 440 | } | 429 | } |
| 441 | res = putenv(v); | 430 | res = putenv(v); |
| 442 | if (res) | 431 | if (res) |
| @@ -343,6 +343,15 @@ | |||
| 343 | "$ echo "Erik\nis\ncool"\n" \ | 343 | "$ echo "Erik\nis\ncool"\n" \ |
| 344 | "Erik\nis\ncool\n" | 344 | "Erik\nis\ncool\n" |
| 345 | 345 | ||
| 346 | #define env_trivial_usage \ | ||
| 347 | "[-] [-iu] [name=value ...] [command]" | ||
| 348 | #define env_full_usage \ | ||
| 349 | "Prints the current environment or runs a program after setting\n" \ | ||
| 350 | "up the specified environment.\n\n" \ | ||
| 351 | "Options:\n" \ | ||
| 352 | "\t-, -i\tstart with an empty environment\n" \ | ||
| 353 | "\t-u\tremove variable from the environment\n" | ||
| 354 | |||
| 346 | #define expr_trivial_usage \ | 355 | #define expr_trivial_usage \ |
| 347 | "EXPRESSION" | 356 | "EXPRESSION" |
| 348 | #define expr_full_usage \ | 357 | #define expr_full_usage \ |
