ENV(1)                     POSIX Programmer's Manual                    ENV(1)



PPRROOLLOOGG
       This manual page is part of the POSIX Programmer's Manual.  The OS
       implementation of this interface may differ (consult the corresponding
       OS manual page for details of OS behavior), or the interface may not be
       implemented on OS.

NNAAMMEE
       env -- set the environment for command invocation

SSYYNNOOPPSSIISS
       env [[-i]] [[_n_a_m_e=_v_a_l_u_e]]... [[_u_t_i_l_i_t_y [[_a_r_g_u_m_e_n_t...]]]]

DDEESSCCRRIIPPTTIIOONN
       The _e_n_v utility shall obtain the current environment, modify it
       according to its arguments, then invoke the utility named by the
       _u_t_i_l_i_t_y operand with the modified environment.

       Optional arguments shall be passed to _u_t_i_l_i_t_y.

       If no _u_t_i_l_i_t_y operand is specified, the resulting environment shall be
       written to the standard output, with one _n_a_m_e=_v_a_l_u_e pair per line.

       If the first argument is ''--'', the results are unspecified.

OOPPTTIIOONNSS
       The _e_n_v utility shall conform to the Base Definitions volume of
       POSIX.1-2017, _S_e_c_t_i_o_n _1_2_._2, _U_t_i_l_i_t_y _S_y_n_t_a_x _G_u_i_d_e_l_i_n_e_s, except for the
       unspecified usage of ''--''.

       The following options shall be supported:

       --ii        Invoke _u_t_i_l_i_t_y with exactly the environment specified by the
                 arguments; the inherited environment shall be ignored
                 completely.

OOPPEERRAANNDDSS
       The following operands shall be supported:

       _n_a_m_e=_v_a_l_u_e
                 Arguments of the form _n_a_m_e=_v_a_l_u_e shall modify the execution
                 environment, and shall be placed into the inherited
                 environment before the _u_t_i_l_i_t_y is invoked.

       _u_t_i_l_i_t_y   The name of the utility to be invoked. If the _u_t_i_l_i_t_y operand
                 names any of the special built-in utilities in _S_e_c_t_i_o_n _2_._1_4,
                 _S_p_e_c_i_a_l _B_u_i_l_t_-_I_n _U_t_i_l_i_t_i_e_s, the results are undefined.

       _a_r_g_u_m_e_n_t  A string to pass as an argument for the invoked utility.

SSTTDDIINN
       Not used.

IINNPPUUTT FFIILLEESS
       None.

EENNVVIIRROONNMMEENNTT VVAARRIIAABBLLEESS
       The following environment variables shall affect the execution of _e_n_v:

       _L_A_N_G      Provide a default value for the internationalization
                 variables that are unset or null. (See the Base Definitions
                 volume of POSIX.1-2017, _S_e_c_t_i_o_n _8_._2, _I_n_t_e_r_n_a_t_i_o_n_a_l_i_z_a_t_i_o_n
                 _V_a_r_i_a_b_l_e_s for the precedence of internationalization
                 variables used to determine the values of locale categories.)

       _L_C___A_L_L    If set to a non-empty string value, override the values of
                 all the other internationalization variables.

       _L_C___C_T_Y_P_E  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).

       _L_C___M_E_S_S_A_G_E_S
                 Determine the locale that should be used to affect the format
                 and contents of diagnostic messages written to standard
                 error.

       _N_L_S_P_A_T_H   Determine the location of message catalogs for the processing
                 of _L_C___M_E_S_S_A_G_E_S.

       _P_A_T_H      Determine the location of the _u_t_i_l_i_t_y, as described in the
                 Base Definitions volume of POSIX.1-2017, _C_h_a_p_t_e_r _8,
                 _E_n_v_i_r_o_n_m_e_n_t _V_a_r_i_a_b_l_e_s.  If _P_A_T_H is specified as a _n_a_m_e=_v_a_l_u_e
                 operand to _e_n_v, the _v_a_l_u_e given shall be used in the search
                 for _u_t_i_l_i_t_y.

AASSYYNNCCHHRROONNOOUUSS EEVVEENNTTSS
       Default.

SSTTDDOOUUTT
       If no _u_t_i_l_i_t_y operand is specified, each _n_a_m_e=_v_a_l_u_e pair in the
       resulting environment shall be written in the form:


           "%s=%s\n", <_n_a_m_e>, <_v_a_l_u_e>

       If the _u_t_i_l_i_t_y operand is specified, the _e_n_v utility shall not write to
       standard output.

SSTTDDEERRRR
       The standard error shall be used only for diagnostic messages.

OOUUTTPPUUTT FFIILLEESS
       None.

EEXXTTEENNDDEEDD DDEESSCCRRIIPPTTIIOONN
       None.

EEXXIITT SSTTAATTUUSS
       If _u_t_i_l_i_t_y is invoked, the exit status of _e_n_v shall be the exit status
       of _u_t_i_l_i_t_y; otherwise, the _e_n_v utility shall exit with one of the
       following values:

           0   The _e_n_v utility completed successfully.

       1-125   An error occurred in the _e_n_v utility.

         126   The utility specified by _u_t_i_l_i_t_y was found but could not be
               invoked.

         127   The utility specified by _u_t_i_l_i_t_y could not be found.

CCOONNSSEEQQUUEENNCCEESS OOFF EERRRROORRSS
       Default.

       _T_h_e _f_o_l_l_o_w_i_n_g _s_e_c_t_i_o_n_s _a_r_e _i_n_f_o_r_m_a_t_i_v_e_.

AAPPPPLLIICCAATTIIOONN UUSSAAGGEE
       The _c_o_m_m_a_n_d, _e_n_v, _n_i_c_e, _n_o_h_u_p, _t_i_m_e, and _x_a_r_g_s 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 _e_x_e_c the utility fail with [[EENNOOEENNTT]], and uses 126 when any
       attempt to _e_x_e_c the utility fails for any other reason.

       Historical implementations of the _e_n_v utility use the _e_x_e_c_v_p() or
       _e_x_e_c_l_p() functions defined in the System Interfaces volume of
       POSIX.1-2017 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.

EEXXAAMMPPLLEESS
       The following command:


           env -i PATH=/mybin:"$PATH" $(getconf V7_ENV) mygrep xyz myfile

       invokes the command _m_y_g_r_e_p with a new _P_A_T_H value as the only entry in
       its environment other than any variables required by the implementation
       for conformance. In this case, _P_A_T_H is used to locate _m_y_g_r_e_p, which is
       expected to reside in //mmyybbiinn.

RRAATTIIOONNAALLEE
       As with all other utilities that invoke other utilities, this volume of
       POSIX.1-2017 only specifies what _e_n_v 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 _e_n_v.

       The --ii option was added to allow the functionality of the removed --
       option in a manner compatible with the Utility Syntax Guidelines. It is
       possible to create a non-conforming environment using the --ii option, as
       it may remove environment variables required by the implementation for
       conformance. The following will preserve these environment variables as
       well as preserve the _P_A_T_H for conforming utilities:


           IFS='
           '
           # The preceding value should be <space><tab><newline>.
           # Set IFS to its default value.

           set -f
           # disable pathname expansion

           \unalias -a
           # Unset all possible aliases.
           # Note that unalias is escaped to prevent an alias
           # being used for unalias.
           # This step is not strictly necessary, since aliases are not inherited,
           # and the ENV environment variable is only used by interactive shells,
           # the only way any aliases can exist in a script is if it defines them
           # itself.

           unset -f env getconf
           # Ensure env and getconf are not user functions.

           env -i $(getconf V7_ENV) PATH="$(getconf PATH)" command

       Some have suggested that _e_n_v is redundant since the same effect is
       achieved by:


           name=value ... utility [[ argument ... ]]

       The example is equivalent to _e_n_v 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 _e_n_v utility also writes out the
       current environment if invoked without arguments. There is sufficient
       functionality beyond what the example provides to justify inclusion of
       _e_n_v.

FFUUTTUURREE DDIIRREECCTTIIOONNSS
       None.

SSEEEE AALLSSOO
       _S_e_c_t_i_o_n _2_._1_4, _S_p_e_c_i_a_l _B_u_i_l_t_-_I_n _U_t_i_l_i_t_i_e_s, _S_e_c_t_i_o_n _2_._5, _P_a_r_a_m_e_t_e_r_s _a_n_d
       _V_a_r_i_a_b_l_e_s

       The Base Definitions volume of POSIX.1-2017, _C_h_a_p_t_e_r _8, _E_n_v_i_r_o_n_m_e_n_t
       _V_a_r_i_a_b_l_e_s, _S_e_c_t_i_o_n _1_2_._2, _U_t_i_l_i_t_y _S_y_n_t_a_x _G_u_i_d_e_l_i_n_e_s

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1-2017, Standard for Information Technology --
       Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, 2018 Edition, Copyright (C) 2018 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 .

       Any typographical or formatting errors that appear in this page are
       most likely to have been introduced during the conversion of the source
       files to man page format. To report such errors, see
       https://www.kernel.org/doc/man-pages/reporting_bugs.html .



IEEE/The Open Group                  2017                               ENV(1)
