1.12 exec Command

One exception to the basic command syntax used is the exec command, which takes as an argument another command to execute. What is special about the commands that are executed with exec is that they replace the currently running shell.

A common use of the exec command is in what are known as wrapper scripts. If the purpose of a script is to simply configure and launch another program, then it is known as a wrapper script.

In a wrapper script the last line of the script often uses exec program (where program is the name of another program to execute) to start some other program. A script written this way avoids having a shell continue to run while the program that it launched is running, the result is that this technique saves resources (like RAM).

Although redirection of input and output to a script are discussed in another section, it should also be mentioned that exec can be used to cause redirection for one or more statements in a script.