Mercurial > hg > toybox
annotate toys/posix/env.c @ 653:2986aa63a021
Move commands into "posix", "lsb", and "other" menus/directories.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 25 Aug 2012 14:25:22 -0500 |
parents | toys/env.c@45c10e86be43 |
children | 6df4ccc0acbe |
rev | line source |
---|---|
406 | 1 /* vi: set sw=4 ts=4: |
510
45c10e86be43
Add copyright notice, fluff out help text, use xexec().
Rob Landley <rob@landley.net>
parents:
420
diff
changeset
|
2 * |
45c10e86be43
Add copyright notice, fluff out help text, use xexec().
Rob Landley <rob@landley.net>
parents:
420
diff
changeset
|
3 * env.c - Set the environment for command invocation. |
45c10e86be43
Add copyright notice, fluff out help text, use xexec().
Rob Landley <rob@landley.net>
parents:
420
diff
changeset
|
4 * |
45c10e86be43
Add copyright notice, fluff out help text, use xexec().
Rob Landley <rob@landley.net>
parents:
420
diff
changeset
|
5 * Copyright 2012 Tryn Mirell <tryn@mirell.org> |
406 | 6 * env.c |
7 | |
409
55598a9b8f21
'env' and 'basename' refactored
Tryn Mirell <tryn@mirell.org>
parents:
406
diff
changeset
|
8 USE_ENV(NEWTOY(env, "^i", TOYFLAG_USR|TOYFLAG_BIN)) |
406 | 9 |
10 config ENV | |
11 bool "env" | |
420
eda61bcf575a
Basename and env are usable, default them to y.
Rob Landley <rob@landley.net>
parents:
409
diff
changeset
|
12 default y |
406 | 13 help |
510
45c10e86be43
Add copyright notice, fluff out help text, use xexec().
Rob Landley <rob@landley.net>
parents:
420
diff
changeset
|
14 usage: env [-i] [NAME=VALUE...] [command [option...]] |
409
55598a9b8f21
'env' and 'basename' refactored
Tryn Mirell <tryn@mirell.org>
parents:
406
diff
changeset
|
15 |
510
45c10e86be43
Add copyright notice, fluff out help text, use xexec().
Rob Landley <rob@landley.net>
parents:
420
diff
changeset
|
16 Set the environment for command invocation. |
45c10e86be43
Add copyright notice, fluff out help text, use xexec().
Rob Landley <rob@landley.net>
parents:
420
diff
changeset
|
17 |
45c10e86be43
Add copyright notice, fluff out help text, use xexec().
Rob Landley <rob@landley.net>
parents:
420
diff
changeset
|
18 -i Clear existing environment. |
406 | 19 */ |
20 | |
21 #include "toys.h" | |
22 | |
23 extern char **environ; | |
24 | |
25 void env_main(void) | |
26 { | |
27 char **ev; | |
28 char **command = NULL; | |
409
55598a9b8f21
'env' and 'basename' refactored
Tryn Mirell <tryn@mirell.org>
parents:
406
diff
changeset
|
29 char *del = "="; |
55598a9b8f21
'env' and 'basename' refactored
Tryn Mirell <tryn@mirell.org>
parents:
406
diff
changeset
|
30 |
406 | 31 if (toys.optflags & 1) clearenv(); |
32 | |
33 for (ev = toys.optargs; *ev != NULL; ev++) { | |
409
55598a9b8f21
'env' and 'basename' refactored
Tryn Mirell <tryn@mirell.org>
parents:
406
diff
changeset
|
34 char *env, *val = NULL; |
406 | 35 |
36 env = strtok(*ev, del); | |
37 | |
409
55598a9b8f21
'env' and 'basename' refactored
Tryn Mirell <tryn@mirell.org>
parents:
406
diff
changeset
|
38 if (env) val = strtok(NULL, del); |
406 | 39 |
409
55598a9b8f21
'env' and 'basename' refactored
Tryn Mirell <tryn@mirell.org>
parents:
406
diff
changeset
|
40 if (val) setenv(env, val, 1); |
55598a9b8f21
'env' and 'basename' refactored
Tryn Mirell <tryn@mirell.org>
parents:
406
diff
changeset
|
41 else { |
406 | 42 command = ev; |
43 break; | |
44 } | |
45 } | |
46 | |
47 if (!command) { | |
48 char **ep; | |
510
45c10e86be43
Add copyright notice, fluff out help text, use xexec().
Rob Landley <rob@landley.net>
parents:
420
diff
changeset
|
49 for (ep = environ; *ep; ep++) xputs(*ep); |
409
55598a9b8f21
'env' and 'basename' refactored
Tryn Mirell <tryn@mirell.org>
parents:
406
diff
changeset
|
50 return; |
510
45c10e86be43
Add copyright notice, fluff out help text, use xexec().
Rob Landley <rob@landley.net>
parents:
420
diff
changeset
|
51 } else xexec(command); |
406 | 52 } |