LinuxDevCenter.com

oreilly.comSafari Books Online.Conferences.

We've expanded our Linux news coverage and improved our search! Search for all things Linux across O'Reilly!

Search
Search Tips

advertisement

Listen Print Subscribe to Linux Subscribe to Newsletters

Unix Power Tools
The exec Command

by Mike Loukides and Jerry Peek
02/10/2000

The exec command will execute a command in place of the current shell; that is, it terminates the current shell and starts a new process in its place.

Historically, exec was often used to execute the last command of a shell script. This would kill the shell slightly earlier; otherwise, the shell would wait until the last command was finished. This practice saved a process and some memory. (Aren't you glad you're using a modern system? This sort of conservation usually isn't necessary any longer unless your system limits the number of processes each user can have.)

exec can be used to replace one shell with another shell:

% exec ksh
$

without incurring the additional overhead of having an unused shell waiting for the new shell to finish.

exec also manipulates file descriptors in the Bourne shell. When you use exec to manage file descriptors, it does not replace the current process. For example, the following command makes the standard input of all commands come from the file formfile instead of the default place (usually, your terminal):

exec < formfile


Back More Unix Power Tools

 




Tagged Articles

Be the first to post this article to del.icio.us

Recommended for You

  1. Cover of Linux Server Hacks, Volume Two
    Linux Server Hacks, Volume Two
    Print: $39.99
    Ebook: $31.99
  2. Cover of UNIX in a Nutshell
    UNIX in a Nutshell
    Print: $29.95
  3. Cover of Programming Linux Games
    Programming Linux Games
    Print: $39.95
  4. Cover of Learning GNU Emacs
    Learning GNU Emacs
    Print: $34.95

Sponsored Resources

  • Inside Lightroom
Advertisement

Sponsored by:

O'Reilly Media

©2009, O'Reilly Media, Inc.
(707) 827-7000 / (800) 998-9938
All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners.
About O'Reilly
Academic Solutions
Authors
Contacts
Customer Service
Jobs
Newsletters
O'Reilly Labs
Press Room
Privacy Policy
RSS Feeds
Terms of Service
User Groups
Writing for O'Reilly
Content Archive
Business Technology
Computer Technology
Google
Microsoft
Mobile
Network
Operating System
Digital Photography
Programming
Software
Web
Web Design
More O'Reilly Sites
O'Reilly Radar
Ignite
Tools of Change for Publishing
Digital Media
Inside iPhone
makezine.com
craftzine.com
hackszine.com
perl.com
xml.com

Partner Sites
InsideRIA
java.net
O'Reilly Insights on Forbes.com