Format
exec [–a name]
[command_line]
tcsh shell: exec command
Description
The command_line argument
for exec specifies a command line for another
command. exec runs this command without
creating a new process. Some people picture this action as overlaying the
command on top of the currently running shell. Thus, when the command
exits, control returns to the parent of the shell.
Input and
output redirections are valid in
command_line.
You can change the input and output descriptors of the shell by giving
only input and output redirections in the command. For example:
exec 2>errors
redirects the standard error stream to
errors in all subsequent
commands ran by the shell.
If you do not specify command_line, exec returns
a successful exit status.
In the tcsh shell, exec executes
the specified command in place of the current shell. See tcsh — Invoke a C shell.
Options
- –a name
- The shell passes name as the zero'th argument (argv[0]) to command_line. –a name can
be used to replace the current shell with a new login shell, by specifying
name as a shell with a prefix of a dash (–).
Examples
To replace the current shell process
with a new login shell (which will run the login profiles), specify:
exec -a -sh /bin/sh
Usage notes
exec is
a special built-in shell command.
Localization
exec uses
the following localization environment variables:
- LANG
- LC_ALL
- LC_MESSAGES
- NLSPATH
See Localization for more
information.
Exit values
If you specify
command_line,
exec does
not return to the shell. Instead, the shell exits with the exit status
of
command_line or one of the following
exit status values:
- 1–125
- A redirection error occurred.
- 126
- The command in command_line was found,
but it was not an executable utility.
- 127
- The given command_line could not be
run because the command could not be found in the current PATH environment.
If you did not specify command_line, exec returns
with an exit value of zero.
Portability
POSIX.2, X/Open Portability Guide, UNIX systems.
Related information
sh, tcsh