2013-10-07 16:03:26 +00:00
|
|
|
/* See LICENSE file for copyright and license details. */
|
2013-06-14 16:55:25 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
extern char **environ;
|
|
|
|
|
2014-04-22 13:44:16 +00:00
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
eprintf("usage: env [-i] [-u name]... [name=value]... [cmd [arg...]]\n");
|
|
|
|
}
|
2013-06-14 16:55:25 +00:00
|
|
|
|
|
|
|
int
|
2014-04-18 10:51:18 +00:00
|
|
|
main(int argc, char *argv[])
|
2013-06-14 16:55:25 +00:00
|
|
|
{
|
|
|
|
ARGBEGIN {
|
|
|
|
case 'i':
|
2013-07-18 19:28:08 +00:00
|
|
|
if(environ)
|
|
|
|
*environ = NULL;
|
2013-06-14 16:55:25 +00:00
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
unsetenv(EARGF(usage()));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
} ARGEND;
|
|
|
|
|
|
|
|
for(; *argv && strchr(*argv, '='); argv++)
|
|
|
|
putenv(*argv);
|
|
|
|
|
|
|
|
if(*argv) {
|
|
|
|
execvp(*argv, argv);
|
2014-06-01 12:59:47 +00:00
|
|
|
enprintf(127 - (errno != EEXIST), "env: '%s':", *argv);
|
2013-06-14 16:55:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
while(environ && *environ)
|
2013-07-20 05:27:42 +00:00
|
|
|
printf("%s\n", *environ++);
|
2013-06-14 16:55:25 +00:00
|
|
|
|
2014-10-02 22:46:04 +00:00
|
|
|
return 0;
|
2013-06-14 16:55:25 +00:00
|
|
|
}
|