Exec

From LQWiki
Jump to navigation Jump to search

The exec command is a builtin command of most shells. It is used to run another command, but after the command is run, you will not return to your shell. The new command replaces your shell in memory. When the command ends, the effect will be the same as if you had exited the shell. exec is most useful for running other shells or connecting to another computer with ssh. In these cases, it prevents you from having to exit twice when you want to log out.

The exec() function is a standard library function that achieves the same effect described above. It is typically used in conjunction with fork.

On systems where you don't have permission to use chsh, you can place an exec command in your .profile or .login file to change your shell every time you log in.

Usage and Examples

$ exec command options
$ exec tcsh
$ exec ssh user@otherhost

See also

External links