4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2012, Joyent, Inc. All rights reserved.
26 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
35 * env [ - ] [ name=value ]... [command arg...]
36 * set environment, then execute command (or print environment)
37 * - says start fresh, otherwise merge with inherited environment
53 extern char **environ
;
57 main(int argc
, char **argv
)
64 (void) setlocale(LC_ALL
, "");
66 #if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
67 #define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't */
69 (void) textdomain(TEXT_DOMAIN
);
71 /* check for non-standard "-" option */
72 if ((argc
> 1) && (strcmp(argv
[1], "-")) == 0) {
74 for (i
= 1; i
< argc
; i
++)
80 while ((opt
= getopt(argc
, argv
, "i")) != EOF
) {
91 /* get environment strings */
92 while (argv
[optind
] != NULL
&& strchr(argv
[optind
], '=') != NULL
) {
93 if (putenv(argv
[optind
])) {
94 (void) perror(argv
[optind
]);
100 /* if no utility, output environment strings */
101 if (argv
[optind
] == NULL
) {
106 (void) execvp(argv
[optind
], &argv
[optind
]);
107 (void) fprintf(stderr
, "%s: %s: %s\n", argv
[0], argv
[optind
],
109 exit(((errno
== ENOENT
) || (errno
== ENOTDIR
)) ? 127 : 126);
118 (void) fprintf(stderr
, gettext(
119 "Usage: env [-i] [name=value ...] [utility [argument ...]]\n"
120 " env [-] [name=value ...] [utility [argument ...]]\n"));