mirror of https://github.com/mkerrisk/man-pages
234 lines
7.4 KiB
Groff
234 lines
7.4 KiB
Groff
.\" Copyright (c) 2001-2003 The Open Group, All Rights Reserved
|
|
.TH "ENV" P 2003 "IEEE/The Open Group" "POSIX Programmer's Manual"
|
|
.\" env
|
|
.SH NAME
|
|
env \- set the environment for command invocation
|
|
.SH SYNOPSIS
|
|
.LP
|
|
\fBenv\fP \fB[\fP\fB-i\fP\fB][\fP\fIname\fP\fB=\fP\fIvalue\fP\fB]\fP\fB...\fP
|
|
\fB[\fP\fIutility\fP
|
|
\fB[\fP\fIargument\fP\fB...\fP\fB]]\fP
|
|
.SH DESCRIPTION
|
|
.LP
|
|
The \fIenv\fP utility shall obtain the current environment, modify
|
|
it according to its arguments, then invoke the utility named
|
|
by the \fIutility\fP operand with the modified environment.
|
|
.LP
|
|
Optional arguments shall be passed to \fIutility\fP.
|
|
.LP
|
|
If no \fIutility\fP operand is specified, the resulting environment
|
|
shall be written to the standard output, with one
|
|
\fIname\fP= \fIvalue\fP pair per line.
|
|
.SH OPTIONS
|
|
.LP
|
|
The \fIenv\fP utility shall conform to the Base Definitions volume
|
|
of IEEE\ Std\ 1003.1-2001, Section 12.2, Utility Syntax Guidelines.
|
|
.LP
|
|
The following options shall be supported:
|
|
.TP 7
|
|
\fB-i\fP
|
|
Invoke \fIutility\fP with exactly the environment specified by the
|
|
arguments; the inherited environment shall be ignored
|
|
completely.
|
|
.sp
|
|
.SH OPERANDS
|
|
.LP
|
|
The following operands shall be supported:
|
|
.TP 7
|
|
\fIname\fP=\fIvalue\fP
|
|
Arguments of the form \fIname\fP= \fIvalue\fP shall modify the execution
|
|
environment, and shall be placed into the inherited
|
|
environment before the \fIutility\fP is invoked.
|
|
.TP 7
|
|
\fIutility\fP
|
|
The name of the utility to be invoked. If the \fIutility\fP operand
|
|
names any of the special built-in utilities in \fISpecial Built-In
|
|
Utilities\fP , the results are undefined.
|
|
.TP 7
|
|
\fIargument\fP
|
|
A string to pass as an argument for the invoked utility.
|
|
.sp
|
|
.SH STDIN
|
|
.LP
|
|
Not used.
|
|
.SH INPUT FILES
|
|
.LP
|
|
None.
|
|
.SH ENVIRONMENT VARIABLES
|
|
.LP
|
|
The following environment variables shall affect the execution of
|
|
\fIenv\fP:
|
|
.TP 7
|
|
\fILANG\fP
|
|
Provide a default value for the internationalization variables that
|
|
are unset or null. (See the Base Definitions volume of
|
|
IEEE\ Std\ 1003.1-2001, Section 8.2, Internationalization Variables
|
|
for
|
|
the precedence of internationalization variables used to determine
|
|
the values of locale categories.)
|
|
.TP 7
|
|
\fILC_ALL\fP
|
|
If set to a non-empty string value, override the values of all the
|
|
other internationalization variables.
|
|
.TP 7
|
|
\fILC_CTYPE\fP
|
|
Determine the locale for the interpretation of sequences of bytes
|
|
of text data as characters (for example, single-byte as
|
|
opposed to multi-byte characters in arguments).
|
|
.TP 7
|
|
\fILC_MESSAGES\fP
|
|
Determine the locale that should be used to affect the format and
|
|
contents of diagnostic messages written to standard
|
|
error.
|
|
.TP 7
|
|
\fINLSPATH\fP
|
|
Determine the location of message catalogs for the processing of \fILC_MESSAGES
|
|
\&.\fP
|
|
.TP 7
|
|
\fIPATH\fP
|
|
Determine the location of the \fIutility\fP, as described in the Base
|
|
Definitions volume of IEEE\ Std\ 1003.1-2001, Chapter 8, Environment
|
|
Variables. If \fIPATH\fP is specified as a \fIname\fP= \fIvalue\fP
|
|
operand to \fIenv\fP, the \fIvalue\fP given shall be used in the search
|
|
for \fIutility\fP.
|
|
.sp
|
|
.SH ASYNCHRONOUS EVENTS
|
|
.LP
|
|
Default.
|
|
.SH STDOUT
|
|
.LP
|
|
If no \fIutility\fP operand is specified, each \fIname\fP= \fIvalue\fP
|
|
pair in the resulting environment shall be written in
|
|
the form:
|
|
.sp
|
|
.RS
|
|
.nf
|
|
|
|
\fB"%s=%s\\n", <\fP\fIname\fP\fB>, <\fP\fIvalue\fP\fB>
|
|
\fP
|
|
.fi
|
|
.RE
|
|
.LP
|
|
If the \fIutility\fP operand is specified, the \fIenv\fP utility shall
|
|
not write to standard output.
|
|
.SH STDERR
|
|
.LP
|
|
The standard error shall be used only for diagnostic messages.
|
|
.SH OUTPUT FILES
|
|
.LP
|
|
None.
|
|
.SH EXTENDED DESCRIPTION
|
|
.LP
|
|
None.
|
|
.SH EXIT STATUS
|
|
.LP
|
|
If \fIutility\fP is invoked, the exit status of \fIenv\fP shall be
|
|
the exit status of \fIutility\fP; otherwise, the
|
|
\fIenv\fP utility shall exit with one of the following values:
|
|
.TP 7
|
|
\ \ \ \ 0
|
|
The \fIenv\fP utility completed successfully.
|
|
.TP 7
|
|
1-125
|
|
An error occurred in the \fIenv\fP utility.
|
|
.TP 7
|
|
\ \ 126
|
|
The utility specified by \fIutility\fP was found but could not be
|
|
invoked.
|
|
.TP 7
|
|
\ \ 127
|
|
The utility specified by \fIutility\fP could not be found.
|
|
.sp
|
|
.SH CONSEQUENCES OF ERRORS
|
|
.LP
|
|
Default.
|
|
.LP
|
|
\fIThe following sections are informative.\fP
|
|
.SH APPLICATION USAGE
|
|
.LP
|
|
The \fIcommand\fP, \fIenv\fP, \fInice\fP, \fInohup\fP, \fItime\fP,
|
|
and \fIxargs\fP utilities have been specified to use exit code 127
|
|
if an error occurs so that
|
|
applications can distinguish "failure to find a utility" from "invoked
|
|
utility exited with an error indication". The value 127
|
|
was chosen because it is not commonly used for other meanings; most
|
|
utilities use small values for "normal error conditions" and
|
|
the values above 128 can be confused with termination due to receipt
|
|
of a signal. The value 126 was chosen in a similar manner to
|
|
indicate that the utility could be found, but not invoked. Some scripts
|
|
produce meaningful error messages differentiating the 126
|
|
and 127 cases. The distinction between exit codes 126 and 127 is based
|
|
on KornShell practice that uses 127 when all attempts to
|
|
\fIexec\fP the utility fail with [ENOENT], and uses 126 when any attempt
|
|
to \fIexec\fP the utility fails for any other
|
|
reason.
|
|
.LP
|
|
Historical implementations of the \fIenv\fP utility use the \fIexecvp\fP()
|
|
or \fIexeclp\fP() functions defined in the System Interfaces volume
|
|
of IEEE\ Std\ 1003.1-2001
|
|
to invoke the specified utility; this provides better performance
|
|
and keeps users from having to escape characters with special
|
|
meaning to the shell. Therefore, shell functions, special built-ins,
|
|
and built-ins that are only provided by the shell are not
|
|
found.
|
|
.SH EXAMPLES
|
|
.LP
|
|
The following command:
|
|
.sp
|
|
.RS
|
|
.nf
|
|
|
|
\fBenv -i PATH=/mybin mygrep xyz myfile
|
|
\fP
|
|
.fi
|
|
.RE
|
|
.LP
|
|
invokes the command \fImygrep\fP with a new \fIPATH\fP value as the
|
|
only entry in its environment. In this case, \fIPATH\fP
|
|
is used to locate \fImygrep\fP, which then must reside in \fB/mybin\fP.
|
|
.SH RATIONALE
|
|
.LP
|
|
As with all other utilities that invoke other utilities, this volume
|
|
of IEEE\ Std\ 1003.1-2001 only specifies what
|
|
\fIenv\fP does with standard input, standard output, standard error,
|
|
input files, and output files. If a utility is executed, it
|
|
is not constrained by the specification of input and output by \fIenv\fP.
|
|
.LP
|
|
The \fB-i\fP option was added to allow the functionality of the withdrawn
|
|
\fB-\fP option in a manner compatible with the
|
|
Utility Syntax Guidelines.
|
|
.LP
|
|
Some have suggested that \fIenv\fP is redundant since the same effect
|
|
is achieved by:
|
|
.sp
|
|
.RS
|
|
.nf
|
|
|
|
\fBname=value ... utility\fP \fB[\fP \fBargument ...\fP \fB]\fP
|
|
.fi
|
|
.RE
|
|
.LP
|
|
The example is equivalent to \fIenv\fP when an environment variable
|
|
is being added to the environment of the command, but not
|
|
when the environment is being set to the given value. The \fIenv\fP
|
|
utility also writes out the current environment if invoked
|
|
without arguments. There is sufficient functionality beyond what the
|
|
example provides to justify inclusion of \fIenv\fP.
|
|
.SH FUTURE DIRECTIONS
|
|
.LP
|
|
None.
|
|
.SH SEE ALSO
|
|
.LP
|
|
\fIParameters and Variables\fP , \fISpecial
|
|
Built-In Utilities\fP
|
|
.SH COPYRIGHT
|
|
Portions of this text are reprinted and reproduced in electronic form
|
|
from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
|
|
-- Portable Operating System Interface (POSIX), The Open Group Base
|
|
Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
|
|
Electrical and Electronics Engineers, Inc and The Open Group. In the
|
|
event of any discrepancy between this version and the original IEEE and
|
|
The Open Group Standard, the original IEEE and The Open Group Standard
|
|
is the referee document. The original Standard can be obtained online at
|
|
http://www.opengroup.org/unix/online.html .
|