5.10. exec

The exec command is used to replace the current shell; in other words a subshell is not started. When using this command all existing environments are cleared to start afresh. The general format is:

exec command 

where command is generally a script.

The best description I can think of in explaining exec is to think of it as trampling over your current shell.

When the script has finished the session can be terminated. One of the many uses of exec is to run added security scripts, usually put at the end of the user’s .profile file. If the user inputs an invalid response, the shell is closed and they are back at the login prompt. Exec is also popular when opening files with file descriptors.

Be aware when using exec with file descriptors ...

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.