1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#define FOR_env
25#include "toys.h"
26
27GLOBALS(
28 struct arg_list *u;
29);
30
31extern char **environ;
32
33void env_main(void)
34{
35 char **ev = toys.optargs;
36
37
38 if (*ev && **ev == '-' && !(*ev)[1]) {
39 toys.optflags |= FLAG_i;
40 ev++;
41 }
42
43 if (toys.optflags & FLAG_i) clearenv();
44 while (TT.u) {
45 unsetenv(TT.u->arg);
46 TT.u = TT.u->next;
47 }
48
49 for (; *ev; ev++) {
50 char *name = *ev, *val = strchr(name, '=');
51
52 if (val) {
53 *(val++) = 0;
54 setenv(name, val, 1);
55 } else xexec(ev);
56 }
57
58 if (environ) for (ev = environ; *ev; ev++)
59 xprintf("%s%c", *ev, '\n'*!(toys.optflags&FLAG_0));
60}
61