O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required