1EXEC(1P)                   POSIX Programmer's Manual                  EXEC(1P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10
11

NAME

13       exec — execute commands and open, close, or copy file descriptors
14

SYNOPSIS

16       exec [command [argument...]]
17

DESCRIPTION

19       The exec utility shall open, close, and/or  copy  file  descriptors  as
20       specified by any redirections as part of the command.
21
22       If  exec  is  specified  without  command  or  arguments,  and any file
23       descriptors with numbers greater than 2 are opened with associated  re‐
24       direction  statements, it is unspecified whether those file descriptors
25       remain open when the shell invokes another utility.  Scripts  concerned
26       that  child  shells could misuse open file descriptors can always close
27       them explicitly, as shown in one of the following examples.
28
29       If exec is specified with command, it shall replace the shell with com‐
30       mand  without  creating a new process. If arguments are specified, they
31       shall be arguments to command.  Redirection affects the  current  shell
32       execution environment.
33

OPTIONS

35       None.
36

OPERANDS

38       See the DESCRIPTION.
39

STDIN

41       Not used.
42

INPUT FILES

44       None.
45

ENVIRONMENT VARIABLES

47       None.
48

ASYNCHRONOUS EVENTS

50       Default.
51

STDOUT

53       Not used.
54

STDERR

56       The standard error shall be used only for diagnostic messages.
57

OUTPUT FILES

59       None.
60

EXTENDED DESCRIPTION

62       None.
63

EXIT STATUS

65       If  command  is  specified, exec shall not return to the shell; rather,
66       the exit status of the process shall be the exit status of the  program
67       implementing  command,  which  overlaid  the  shell.  If command is not
68       found, the exit status shall be 127. If command is found, but it is not
69       an  executable  utility, the exit status shall be 126. If a redirection
70       error occurs (see Section 2.8.1, Consequences  of  Shell  Errors),  the
71       shell shall exit with a value in the range 1−125. Otherwise, exec shall
72       return a zero exit status.
73

CONSEQUENCES OF ERRORS

75       Default.
76
77       The following sections are informative.
78

APPLICATION USAGE

80       None.
81

EXAMPLES

83       Open readfile as file descriptor 3 for reading:
84
85           exec 3< readfile
86
87       Open writefile as file descriptor 4 for writing:
88
89           exec 4> writefile
90
91       Make file descriptor 5 a copy of file descriptor 0:
92
93           exec 5<&0
94
95       Close file descriptor 3:
96
97           exec 3<&−
98
99       Cat the file maggie by replacing the current shell with the  cat  util‐
100       ity:
101
102           exec cat maggie
103

RATIONALE

105       Most historical implementations were not conformant in that:
106
107           foo=bar exec cmd
108
109       did not pass foo to cmd.
110

FUTURE DIRECTIONS

112       None.
113

SEE ALSO

115       Section 2.14, Special Built-In Utilities
116
118       Portions  of  this text are reprinted and reproduced in electronic form
119       from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology
120       --  Portable  Operating  System  Interface (POSIX), The Open Group Base
121       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
122       cal  and  Electronics  Engineers,  Inc  and  The  Open Group.  (This is
123       POSIX.1-2008 with the 2013 Technical Corrigendum  1  applied.)  In  the
124       event of any discrepancy between this version and the original IEEE and
125       The Open Group Standard, the original IEEE and The Open Group  Standard
126       is  the  referee document. The original Standard can be obtained online
127       at http://www.unix.org/online.html .
128
129       Any typographical or formatting errors that appear  in  this  page  are
130       most likely to have been introduced during the conversion of the source
131       files to man page format. To report such errors,  see  https://www.ker
132       nel.org/doc/man-pages/reporting_bugs.html .
133
134
135
136IEEE/The Open Group                  2013                             EXEC(1P)
Impressum