env.c revision 24360
134192Sjdp/* 255687Sjdp * Copyright (c) 1988, 1993, 1994 334192Sjdp * The Regents of the University of California. All rights reserved. 434192Sjdp * 534192Sjdp * Redistribution and use in source and binary forms, with or without 634192Sjdp * modification, are permitted provided that the following conditions 734192Sjdp * are met: 834192Sjdp * 1. Redistributions of source code must retain the above copyright 934192Sjdp * notice, this list of conditions and the following disclaimer. 1034192Sjdp * 2. Redistributions in binary form must reproduce the above copyright 1134192Sjdp * notice, this list of conditions and the following disclaimer in the 1234192Sjdp * documentation and/or other materials provided with the distribution. 1334192Sjdp * 3. All advertising materials mentioning features or use of this software 1434192Sjdp * must display the following acknowledgement: 1534192Sjdp * This product includes software developed by the University of 1634192Sjdp * California, Berkeley and its contributors. 1734192Sjdp * 4. Neither the name of the University nor the names of its contributors 1834192Sjdp * may be used to endorse or promote products derived from this software 1934192Sjdp * without specific prior written permission. 2034192Sjdp * 2134192Sjdp * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2234192Sjdp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2334192Sjdp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2434192Sjdp * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2550476Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2634192Sjdp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2734192Sjdp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2834192Sjdp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2934192Sjdp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3034192Sjdp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3176224Sobrien * SUCH DAMAGE. 3234192Sjdp */ 3350608Sjdp 3434192Sjdp#ifndef lint 3576224Sobrienstatic char copyright[] = 3635529Sdfr"@(#) Copyright (c) 1988, 1993, 1994\n\ 3734192Sjdp The Regents of the University of California. All rights reserved.\n"; 3834192Sjdp#endif /* not lint */ 39115396Skan 4045501Sjdp#ifndef lint 4145501Sjdpstatic char sccsid[] = "@(#)env.c 8.3 (Berkeley) 4/2/94"; 4234192Sjdp#endif /* not lint */ 43110801Skan 4434192Sjdp#include <err.h> 4534192Sjdp#include <stdio.h> 4634192Sjdp#include <string.h> 4734192Sjdp#include <stdlib.h> 4834192Sjdp#include <unistd.h> 4934192Sjdp 5034192Sjdpextern char **environ; 5134192Sjdp 5234192Sjdpint 5334192Sjdpmain(argc, argv) 5450609Sjdp int argc; 5534192Sjdp char **argv; 5634192Sjdp{ 5755687Sjdp char **ep, *p; 5850608Sjdp char *cleanenv[1]; 5960938Sjake int ch; 6050608Sjdp 6150608Sjdp while ((ch = getopt(argc, argv, "-")) != -1) 6250608Sjdp switch(ch) { 6360938Sjake case '-': 6450608Sjdp environ = cleanenv; 6563870Sjdp cleanenv[0] = NULL; 6655687Sjdp break; 6755687Sjdp case '?': 6855687Sjdp default: 6934192Sjdp (void)fprintf(stderr, 7034192Sjdp "usage: env [-] [name=value ...] [command]\n"); 7134192Sjdp exit(1); 7234192Sjdp } 7334192Sjdp for (argv += optind; *argv && (p = strchr(*argv, '=')); ++argv) 7434192Sjdp (void)setenv(*argv, ++p, 1); 7562801Sjdp if (*argv) { 7662801Sjdp execvp(*argv, argv); 7762801Sjdp err(1, "%s", *argv); 7862801Sjdp } 7962801Sjdp for (ep = environ; *ep; ep++) 8062801Sjdp (void)printf("%s\n", *ep); 8162801Sjdp exit(0); 8262801Sjdp} 8362801Sjdp