1exec(1) User Commands exec(1)
2
3
4
6 exec, eval, source - shell built-in functions to execute other commands
7
9 sh
10 exec [argument]...
11
12
13 eval [argument]...
14
15
16 csh
17 exec command
18
19
20 eval argument...
21
22
23 source [-h] name
24
25
26 ksh
27 *exec [argument]...
28
29
30 *eval [argument]...
31
32
33 ksh93
34 +exec [-c] [-a name] [command [argument ... ]]
35
36
37 +eval [argument]...
38
39
41 sh
42 The exec command specified by the arguments is executed in place of
43 this shell without creating a new process. Input/output arguments and
44 appear and, if no other arguments are specified, cause the shell
45 input/output to be modified.
46
47
48 The arguments to the eval built-in are read as input to the shell and
49 the resulting command(s) executed.
50
51 csh
52 exec executes command in place of the current shell, which terminates.
53
54
55 eval reads its arguments as input to the shell and executes the result‐
56 ing command(s). This is usually used to execute commands generated as
57 the result of command or variable substitution.
58
59
60 source reads commands from name. source commands can be nested, but if
61 they are nested too deeply the shell can run out of file descriptors.
62 An error in a sourced file at any level terminates all nested source
63 commands.
64
65 -h Place commands from the file name on the history list without
66 executing them.
67
68
69 ksh
70 With the exec built-in, if arg is specified, the command specified by
71 the arguments is executed in place of this shell without creating a new
72 process. Input/output arguments can appear and affect the current
73 process. If no arguments are specified the effect of this command is to
74 modify file descriptors as prescribed by the input/output redirection
75 list. In this case, any file descriptor numbers greater than 2 that are
76 opened with this mechanism are closed when invoking another program.
77
78
79 The arguments to eval are read as input to the shell and the resulting
80 command(s) executed.
81
82
83 On this man page, ksh(1) commands that are preceded by one or two *
84 (asterisks) are treated specially in the following ways:
85
86 1. Variable assignment lists preceding the command remain in
87 effect when the command completes.
88
89 2. I/O redirections are processed after variable assignments.
90
91 3. Errors cause a script that contains them to abort.
92
93 4. Words, following a command preceded by ** that are in the
94 format of a variable assignment, are expanded with the same
95 rules as a variable assignment. This means that tilde sub‐
96 stitution is performed after the = sign and word splitting
97 and file name generation are not performed.
98
99 ksh93
100 exec is a special built-in command that can be used to manipulate file
101 descriptors or to replace the current shell with a new command.
102
103
104 If command is specified, then the current shell process is replaced by
105 command rather than running command and waiting for it to complete.
106 There is no need to use exec to enhance performance since the shell
107 implicitly uses the exec mechanism internally whenever possible.
108
109
110 If no operands are specified, exec can be used to open or close files,
111 or to manipulate file descriptors from 0 to 9 in the current shell
112 environment using the standard redirection mechanism available with all
113 commands. The close-on-exec flags is set on file descriptor numbers
114 greater than 2 that are opened this way so that they are closed when
115 another program is invoked.
116
117
118 Because exec is a special command, any failure causes the script that
119 invokes it to exit. This can be prevented by invoking exec from the
120 command utility.
121
122
123 exec cannot be invoked from a restricted shell to create files or to
124 open a file for writing or appending.
125
126
127 eval is a shell special built-in command that constructs a command by
128 concatenating the arguments together, separating each with a space. The
129 resulting string is taken as input to the shell and evaluated in the
130 current environment. command words are expanded twice, once to con‐
131 struct argument, and again when the shell executes the constructed com‐
132 mand. It is not an error if argument is not specified.
133
134
135 On this manual page, ksh93 commands that are preceded by one or two +
136 symbols are special built-in commands and are treated specially in the
137 following ways:
138
139 1. Variable assignment lists preceding the command remain in
140 effect when the command completes.
141
142 2. I/O redirections are processed after variable assignments.
143
144 3. Errors cause a script that contains them to abort.
145
146 4. They are not valid function names.
147
148 5. Words following a command preceded by ++ that are in the
149 format of a variable assignment are expanded with the same
150 rules as a variable assignment. This means that tilde sub‐
151 stitution is performed after the = sign and field splitting
152 and file name generation are not performed.
153
155 ksh93
156 The following options are supported by ksh93 exec:
157
158 -a name argv[0] is set to name for command.
159
160
161 -c Clear all environment variables before executions except
162 variable assignments that are part of the current exec com‐
163 mand.
164
165
167 ksh
168 The following exit values are returned by exec:
169
170 0 Successful completion.
171
172
173 1-125 A redirection error occurred.
174
175
176 127 command was not found.
177
178
179 126 command was found, but it is not an executable utility.
180
181
182 ksh93
183 The following exit values are returned by exec. If command is speci‐
184 fied, exec does not return.
185
186 0 Successful completion. All I/O redirections were successful.
187
188
189 >0 An error occurred.
190
191
192
193 The following exit values are returned by eval:
194
195
196 If argument is not specified, the exit status is 0. Otherwise, it is
197 the exit status of the command defined by the argument operands.
198
200 See attributes(5) for descriptions of the following attributes:
201
202
203
204
205 ┌─────────────────────────────┬─────────────────────────────┐
206 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
207 ├─────────────────────────────┼─────────────────────────────┤
208 │Availability │SUNWcsu │
209 └─────────────────────────────┴─────────────────────────────┘
210
212 csh(1), ksh(1), ksh93(1), sh(1), attributes(5)
213
214
215
216SunOS 5.11 8 Apr 2008 exec(1)