exec — Run a command and open, close, or copy the file descriptors
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.
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
exec -a -sh /bin/sh
Usage notes
exec is a special built-in shell command.
Localization
- LANG
- LC_ALL
- LC_MESSAGES
- NLSPATH
See Localization for more information.
Exit 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