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