1 /* env.c - Set the environment for command invocation. 2 * 3 * Copyright 2012 Tryn Mirell <tryn@mirell.org> 4 * 5 * http://opengroup.org/onlinepubs/9699919799/utilities/env.html 6 7 USE_ENV(NEWTOY(env, "^i", TOYFLAG_USR|TOYFLAG_BIN)) 8 9 config ENV 10 bool "env" 11 default y 12 help 13 usage: env [-i] [NAME=VALUE...] [command [option...]] 14 15 Set the environment for command invocation. 16 17 -i Clear existing environment. 18 */ 19 20 #include "toys.h" 21 22 extern char **environ; 23 env_main(void)24void env_main(void) 25 { 26 char **ev; 27 char *del = "="; 28 29 if (toys.optflags) clearenv(); 30 31 for (ev = toys.optargs; *ev != NULL; ev++) { 32 char *env = strtok(*ev, del), *val = 0; 33 34 if (env) val = strtok(0, del); 35 if (val) setenv(env, val, 1); 36 else xexec(ev); 37 } 38 39 if (environ) for (ev = environ; *ev; ev++) xputs(*ev); 40 } 41