1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
'\" te
.\" Copyright 1989 AT&T
.\" Copyright (c) 2007 Sun Microsystems, Inc. - All Rights Reserved.
.\" Portions Copyright (c) 1982-2007 AT&T Knowledge Ventures
.\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
.\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
.\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
.TH EXEC 1 "Apr 8, 2008"
.SH NAME
exec, eval, source \- shell built-in functions to execute other commands
.SH SYNOPSIS
.SS "sh"
.LP
.nf
\fBexec\fR [\fIargument\fR]...
.fi
.LP
.nf
\fBeval\fR [\fIargument\fR]...
.fi
.SS "csh"
.LP
.nf
\fBexec\fR \fIcommand\fR
.fi
.LP
.nf
\fBeval\fR \fIargument\fR...
.fi
.LP
.nf
\fBsource\fR [\fB-h\fR] \fIname\fR
.fi
.SS "ksh"
.LP
.nf
\fB*exec\fR [\fIargument\fR]...
.fi
.LP
.nf
\fB*eval\fR [\fIargument\fR]...
.fi
.SS "ksh93"
.LP
.nf
\fB+exec\fR [\fB-c\fR] [\fB-a\fR \fIname\fR] [\fIcommand\fR [\fIargument\fR ... ]]
.fi
.LP
.nf
\fB+eval\fR [\fIargument\fR]...
.fi
.SH DESCRIPTION
.SS "sh"
.sp
.LP
The \fBexec\fR command specified by the arguments is executed in place of this
shell without creating a new process. Input/output arguments and appear and, if
no other arguments are specified, cause the shell input/output to be modified.
.sp
.LP
The \fIargument\fRs to the \fBeval\fR built-in are read as input to the shell
and the resulting command(s) executed.
.SS "csh"
.sp
.LP
\fBexec\fR executes \fBcommand\fR in place of the current shell, which
terminates.
.sp
.LP
\fBeval\fR reads its \fIargument\fRs as input to the shell and executes the
resulting command(s). This is usually used to execute commands generated as the
result of command or variable substitution.
.sp
.LP
\fBsource\fR reads commands from \fIname\fR. \fBsource\fR commands can be
nested, but if they are nested too deeply the shell can run out of file
descriptors. An error in a sourced file at any level terminates all nested
\fBsource\fR commands.
.sp
.ne 2
.na
\fB\fB-h\fR\fR
.ad
.RS 6n
Place commands from the file \fIname\fR on the history list without executing
them.
.RE
.SS "ksh"
.sp
.LP
With the \fBexec\fR built-in, if \fIarg\fR is specified, the command specified
by the arguments is executed in place of this shell without creating a new
process. Input/output arguments can appear and affect the current process. If
no arguments are specified the effect of this command is to modify file
descriptors as prescribed by the input/output redirection list. In this case,
any file descriptor numbers greater than 2 that are opened with this mechanism
are closed when invoking another program.
.sp
.LP
The arguments to \fBeval\fR are read as input to the shell and the resulting
command(s) executed.
.sp
.LP
On this man page, \fBksh\fR(1) commands that are preceded by one or two *
(asterisks) are treated specially in the following ways:
.RS +4
.TP
1.
Variable assignment lists preceding the command remain in effect when the
command completes.
.RE
.RS +4
.TP
2.
\fBI/O\fR redirections are processed after variable assignments.
.RE
.RS +4
.TP
3.
Errors cause a script that contains them to abort.
.RE
.RS +4
.TP
4.
Words, following a command preceded by ** that are in the format of a
variable assignment, are expanded with the same rules as a variable assignment.
This means that tilde substitution is performed after the \fB=\fR sign and word
splitting and file name generation are not performed.
.RE
.SS "ksh93"
.sp
.LP
\fBexec\fR is a special built-in command that can be used to manipulate file
descriptors or to replace the current shell with a new command.
.sp
.LP
If \fIcommand\fR is specified, then the current shell process is replaced by
\fIcommand\fR rather than running \fIcommand\fR and waiting for it to complete.
There is no need to use \fBexec\fR to enhance performance since the shell
implicitly uses the \fBexec\fR mechanism internally whenever possible.
.sp
.LP
If no operands are specified, \fBexec\fR can be used to open or close files, or
to manipulate file descriptors from \fB0\fR to \fB9\fR in the current shell
environment using the standard redirection mechanism available with all
commands. The close-on-exec flags is set on file descriptor numbers greater
than \fB2\fR that are opened this way so that they are closed when another
program is invoked.
.sp
.LP
Because \fBexec\fR is a special command, any failure causes the script that
invokes it to exit. This can be prevented by invoking \fBexec\fR from the
\fBcommand\fR utility.
.sp
.LP
\fBexec\fR cannot be invoked from a restricted shell to create files or to open
a file for writing or appending.
.sp
.LP
\fBeval\fR is a shell special built-in command that constructs a command by
concatenating the \fIargument\fRs together, separating each with a space. The
resulting string is taken as input to the shell and evaluated in the current
environment. command words are expanded twice, once to construct
\fIargument\fR, and again when the shell executes the constructed command. It
is not an error if \fIargument\fR is not specified.
.sp
.LP
On this manual page, \fBksh93\fR commands that are preceded by one or two
\fB+\fR symbols are special built-in commands and are treated specially in the
following ways:
.RS +4
.TP
1.
Variable assignment lists preceding the command remain in effect when the
command completes.
.RE
.RS +4
.TP
2.
I/O redirections are processed after variable assignments.
.RE
.RS +4
.TP
3.
Errors cause a script that contains them to abort.
.RE
.RS +4
.TP
4.
They are not valid function names.
.RE
.RS +4
.TP
5.
Words following a command preceded by \fB++\fR that are in the format of a
variable assignment are expanded with the same rules as a variable assignment.
This means that tilde substitution is performed after the \fB=\fR sign and
field splitting and file name generation are not performed.
.RE
.SH OPTIONS
.SS "ksh93"
.sp
.LP
The following options are supported by \fBksh93 exec\fR:
.sp
.ne 2
.na
\fB\fB-a\fR \fIname\fR\fR
.ad
.RS 11n
\fBargv[0]\fR is set to \fIname\fR for command.
.RE
.sp
.ne 2
.na
\fB\fB-c\fR\fR
.ad
.RS 11n
Clear all environment variables before executions except variable assignments
that are part of the current \fBexec\fR command.
.RE
.SH EXIT STATUS
.SS "ksh"
.sp
.LP
The following exit values are returned by \fBexec\fR:
.sp
.ne 2
.na
\fB\fB0\fR\fR
.ad
.RS 9n
Successful completion.
.RE
.sp
.ne 2
.na
\fB\fB1-125\fR\fR
.ad
.RS 9n
A redirection error occurred.
.RE
.sp
.ne 2
.na
\fB\fB127\fR\fR
.ad
.RS 9n
\fIcommand\fR was not found.
.RE
.sp
.ne 2
.na
\fB\fB126\fR\fR
.ad
.RS 9n
\fIcommand\fR was found, but it is not an executable utility.
.RE
.SS "ksh93"
.sp
.LP
The following exit values are returned by \fBexec\fR. If \fIcommand\fR is
specified, \fBexec\fR does not return.
.sp
.ne 2
.na
\fB\fB0\fR\fR
.ad
.RS 6n
Successful completion. All I/O redirections were successful.
.RE
.sp
.ne 2
.na
\fB\fB>0\fR\fR
.ad
.RS 6n
An error occurred.
.RE
.sp
.LP
The following exit values are returned by \fBeval\fR:
.sp
.LP
If \fIargument\fR is not specified, the exit status is \fB0\fR. Otherwise, it
is the exit status of the command defined by the \fIargument\fR operands.
.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(7) for descriptions of the following attributes:
.sp
.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE ATTRIBUTE VALUE
.TE
.SH SEE ALSO
.sp
.LP
.BR csh (1),
.BR ksh (1),
.BR ksh93 (1),
.BR sh (1),
.BR attributes (7)
|