diff options
-rw-r--r-- | coreutils/env.c | 2 | ||||
-rw-r--r-- | coreutils/printenv.c | 23 |
2 files changed, 10 insertions, 15 deletions
diff --git a/coreutils/env.c b/coreutils/env.c index 31167d029..3008358ec 100644 --- a/coreutils/env.c +++ b/coreutils/env.c | |||
@@ -63,7 +63,7 @@ int env_main(int argc, char** argv) | |||
63 | if (opt & 1) { | 63 | if (opt & 1) { |
64 | cleanenv[0] = NULL; | 64 | cleanenv[0] = NULL; |
65 | environ = cleanenv; | 65 | environ = cleanenv; |
66 | } else if (opt & 2) { | 66 | } else { |
67 | while (unset_env) { | 67 | while (unset_env) { |
68 | unsetenv(unset_env->data); | 68 | unsetenv(unset_env->data); |
69 | unset_env = unset_env->link; | 69 | unset_env = unset_env->link; |
diff --git a/coreutils/printenv.c b/coreutils/printenv.c index 2531d5a23..19fa832c8 100644 --- a/coreutils/printenv.c +++ b/coreutils/printenv.c | |||
@@ -14,25 +14,20 @@ extern char **environ; | |||
14 | int printenv_main(int argc, char **argv); | 14 | int printenv_main(int argc, char **argv); |
15 | int printenv_main(int argc, char **argv) | 15 | int printenv_main(int argc, char **argv) |
16 | { | 16 | { |
17 | int e = 0; | ||
18 | |||
19 | /* no variables specified, show whole env */ | 17 | /* no variables specified, show whole env */ |
20 | if (argc == 1) | 18 | if (argc == 1) { |
19 | int e = 0; | ||
21 | while (environ[e]) | 20 | while (environ[e]) |
22 | puts(environ[e++]); | 21 | puts(environ[e++]); |
23 | 22 | } else { | |
24 | /* search for specified variables and print them out if found */ | 23 | /* search for specified variables and print them out if found */ |
25 | else { | ||
26 | int i; | ||
27 | size_t l; | ||
28 | char *arg, *env; | 24 | char *arg, *env; |
29 | 25 | ||
30 | for (i=1; (arg = argv[i]); ++i) | 26 | while ((arg = *++argv) != NULL) { |
31 | for (; (env = environ[e]); ++e) { | 27 | env = getenv(arg); |
32 | l = strlen(arg); | 28 | if (env) |
33 | if (!strncmp(env, arg, l) && env[l] == '=') | 29 | puts(env); |
34 | puts(env + l + 1); | 30 | } |
35 | } | ||
36 | } | 31 | } |
37 | 32 | ||
38 | fflush_stdout_and_exit(0); | 33 | fflush_stdout_and_exit(0); |