EXEC(1)                    POSIX Programmer's Manual                   EXEC(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
       exec -- execute commands and open, close, or copy file descriptors

SSYYNNOOPPSSIISS
       exec [[_c_o_m_m_a_n_d [[_a_r_g_u_m_e_n_t...]]]]

DDEESSCCRRIIPPTTIIOONN
       The _e_x_e_c utility shall open, close, and/or copy file descriptors as
       specified by any redirections as part of the command.

       If _e_x_e_c is specified without _c_o_m_m_a_n_d or _a_r_g_u_m_e_n_ts, and any file
       descriptors with numbers greater than 2 are opened with associated
       redirection statements, it is unspecified whether those file
       descriptors remain open when the shell invokes another utility.
       Scripts concerned that child shells could misuse open file descriptors
       can always close them explicitly, as shown in one of the following
       examples.

       If _e_x_e_c is specified with _c_o_m_m_a_n_d, it shall replace the shell with
       _c_o_m_m_a_n_d without creating a new process. If _a_r_g_u_m_e_n_ts are specified,
       they shall be arguments to _c_o_m_m_a_n_d.  Redirection affects the current
       shell execution environment.

OOPPTTIIOONNSS
       None.

OOPPEERRAANNDDSS
       See the DESCRIPTION.

SSTTDDIINN
       Not used.

IINNPPUUTT FFIILLEESS
       None.

EENNVVIIRROONNMMEENNTT VVAARRIIAABBLLEESS
       None.

AASSYYNNCCHHRROONNOOUUSS EEVVEENNTTSS
       Default.

SSTTDDOOUUTT
       Not used.

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

OOUUTTPPUUTT FFIILLEESS
       None.

EEXXTTEENNDDEEDD DDEESSCCRRIIPPTTIIOONN
       None.

EEXXIITT SSTTAATTUUSS
       If _c_o_m_m_a_n_d is specified, _e_x_e_c shall not return to the shell; rather,
       the exit status of the process shall be the exit status of the program
       implementing _c_o_m_m_a_n_d, which overlaid the shell. If _c_o_m_m_a_n_d is not
       found, the exit status shall be 127. If _c_o_m_m_a_n_d is found, but it is not
       an executable utility, the exit status shall be 126. If a redirection
       error occurs (see _S_e_c_t_i_o_n _2_._8_._1, _C_o_n_s_e_q_u_e_n_c_e_s _o_f _S_h_e_l_l _E_r_r_o_r_s), the
       shell shall exit with a value in the range 1-125. Otherwise, _e_x_e_c shall
       return a zero exit status.

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
       None.

EEXXAAMMPPLLEESS
       Open _r_e_a_d_f_i_l_e as file descriptor 3 for reading:

           eexxeecc 33<< rreeaaddffiillee

       Open _w_r_i_t_e_f_i_l_e as file descriptor 4 for writing:

           eexxeecc 44>> wwrriitteeffiillee

       Make file descriptor 5 a copy of file descriptor 0:

           eexxeecc 55<<&&00

       Close file descriptor 3:

           eexxeecc 33<<&&--

       Cat the file mmaaggggiiee by replacing the current shell with the _c_a_t
       utility:

           eexxeecc ccaatt mmaaggggiiee

RRAATTIIOONNAALLEE
       Most historical implementations were not conformant in that:

           ffoooo==bbaarr eexxeecc ccmmdd

       did not pass ffoooo to ccmmdd.

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

CCOOPPYYRRIIGGHHTT
       Portions of this text are reprinted and reproduced in electronic form
       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
       -- Portable Operating System Interface (POSIX), The Open Group Base
       Specifications Issue 7, Copyright (C) 2013 by the Institute of
       Electrical and Electronics Engineers, Inc and The Open Group.  (This is
       POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) 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.unix.org/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                  2013                              EXEC(1)
