unix 下的C开发手册,还用详细的例程。
源代码在线查看: env.html
env The Single UNIX ® Specification, Version 2 Copyright © 1997 The Open Group NAME env - set the environment for command invocation SYNOPSIS env [-i][name=value]... [utility [argument...]] env [-][name=value]... [utility [argument...]] DESCRIPTION The env utility will obtain the current environment, modify it according to its arguments, then invoke the utility named by the utility operand with the modified environment. Optional arguments will be passed to utility. If no utility operand is specified, the resulting environment will be written to the standard output, with one name=value pair per line. OPTIONS The env utility supports the XBD specification, Utility Syntax Guidelines , except for its non-standard usage of "-". The following options are supported: -i - Invoke utility with exactly the environment specified by the arguments; the inherited environment will be ignored completely. OPERANDS The following operands are supported: name=value Arguments of the form name=value modify the execution environment, and are placed into the inherited environment before the utility is invoked. utilityThe name of the utility to be invoked. If the utility operand names any of the special built-in utilities in Special Built-in Utilities , the results are undefined. argument A string to pass as an argument for the invoked utility. STDIN Not used. INPUT FILES None. ENVIRONMENT VARIABLES The following environment variables affect the execution of env: LANGProvide a default value for the internationalisation variables that are unset or null. If LANG is unset or null, the corresponding value from the implementation-dependent default locale will be used. If any of the internationalisation variables contains an invalid setting, the utility will behave as if none of the variables had been defined. LC_ALL If set to a non-empty string value, override the values of all the other internationalisation variables. LC_CTYPE Determine the locale for the interpretation of sequences of bytes of text data as characters (for example, single- as opposed to multi-byte characters in arguments). LC_MESSAGES Determine the locale that should be used to affect the format and contents of diagnostic messages written to standard error. NLSPATH Determine the location of message catalogues for the processing of LC_MESSAGES . PATHDetermine the location of the utility, as described in the XBD specification, Environment Variables . If PATH is specified as a name=value operand to env, the value given will be used in the search for utility. ASYNCHRONOUS EVENTS Default. STDOUT If no utility operand is specified, each name=value pair in the resulting environment will be written in the form: "%s=%s\n", <name>, <value> If the utility operand is specified, the env utility will not write to standard output. STDERR Used only for diagnostic messages. OUTPUT FILES None. EXTENDED DESCRIPTION None. EXIT STATUS If the utility utility is invoked, the exit status of env will be the exit status of utility; otherwise, the env utility will exit with one of the following values: 0The env utility completed successfully. 1-125An error occurred in the env utility. 126The utility specified by utility was found but could not be invoked. 127The utility specified by utility could not be found. CONSEQUENCES OF ERRORS Default. APPLICATION USAGE The command, env, nice, nohup, time and xargs 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 exec the utility fail with [ENOENT], and uses 126 when any attempt to exec the utility fails for any other reason. Historical implementations of the env utility use the XSH specification execvp() or execlp() functions 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. EXAMPLES The following command: env -i PATH=/mybin mygrep xyz myfile invokes the command mygrep with a new PATH value as the only entry in its environment. In this case, PATH is used to locate mygrep, which then must reside in /mybin. FUTURE DIRECTIONS None. SEE ALSO Parameters and Variables . UNIX ® is a registered Trademark of The Open Group. Copyright © 1997 The Open Group [ Main Index | XSH | XCU | XBD | XCURSES | XNS ]