1EXEC(1P) POSIX Programmer's Manual EXEC(1P)
2
3
4
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
12 exec — execute commands and open, close, or copy file descriptors
13
15 exec [command [argument...]]
16
18 The exec utility shall open, close, and/or copy file descriptors as
19 specified by any redirections as part of the command.
20
21 If exec is specified without command or arguments, and any file
22 descriptors with numbers greater than 2 are opened with associated re‐
23 direction statements, it is unspecified whether those file descriptors
24 remain open when the shell invokes another utility. Scripts concerned
25 that child shells could misuse open file descriptors can always close
26 them explicitly, as shown in one of the following examples.
27
28 If exec is specified with command, it shall replace the shell with com‐
29 mand without creating a new process. If arguments are specified, they
30 shall be arguments to command. Redirection affects the current shell
31 execution environment.
32
34 None.
35
37 See the DESCRIPTION.
38
40 Not used.
41
43 None.
44
46 None.
47
49 Default.
50
52 Not used.
53
55 The standard error shall be used only for diagnostic messages.
56
58 None.
59
61 None.
62
64 If command is specified, exec shall not return to the shell; rather,
65 the exit status of the process shall be the exit status of the program
66 implementing command, which overlaid the shell. If command is not
67 found, the exit status shall be 127. If command is found, but it is not
68 an executable utility, the exit status shall be 126. If a redirection
69 error occurs (see Section 2.8.1, Consequences of Shell Errors), the
70 shell shall exit with a value in the range 1-125. Otherwise, exec shall
71 return a zero exit status.
72
74 Default.
75
76 The following sections are informative.
77
79 None.
80
82 Open readfile as file descriptor 3 for reading:
83
84
85 exec 3< readfile
86
87 Open writefile as file descriptor 4 for writing:
88
89
90 exec 4> writefile
91
92 Make file descriptor 5 a copy of file descriptor 0:
93
94
95 exec 5<&0
96
97 Close file descriptor 3:
98
99
100 exec 3<&-
101
102 Cat the file maggie by replacing the current shell with the cat util‐
103 ity:
104
105
106 exec cat maggie
107
109 Most historical implementations were not conformant in that:
110
111
112 foo=bar exec cmd
113
114 did not pass foo to cmd.
115
117 None.
118
120 Section 2.14, Special Built-In Utilities
121
123 Portions of this text are reprinted and reproduced in electronic form
124 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
125 table Operating System Interface (POSIX), The Open Group Base Specifi‐
126 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
127 Electrical and Electronics Engineers, Inc and The Open Group. In the
128 event of any discrepancy between this version and the original IEEE and
129 The Open Group Standard, the original IEEE and The Open Group Standard
130 is the referee document. The original Standard can be obtained online
131 at http://www.opengroup.org/unix/online.html .
132
133 Any typographical or formatting errors that appear in this page are
134 most likely to have been introduced during the conversion of the source
135 files to man page format. To report such errors, see https://www.ker‐
136 nel.org/doc/man-pages/reporting_bugs.html .
137
138
139
140IEEE/The Open Group 2017 EXEC(1P)