help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] When to use exec to run a program?


From: Greg Wooledge
Subject: Re: [Help-bash] When to use exec to run a program?
Date: Mon, 6 Jun 2016 08:09:51 -0400
User-agent: Mutt/1.4.2.3i

On Fri, Jun 03, 2016 at 08:25:45PM -0500, Peng Yu wrote:
> In this case, should I always use exec whenever possible? For example,
> would something like the following be preferred in a pipeline?
> 
> exec cmd1 | exec cmd2

I believe bash is clever enough to optimize each part of the pipeline
to avoid the extra fork(), but I'm not 100% sure of that.  In any case,
nobody writes shell scripts like that.

exec is used in two cases:

1) To open, close or duplicate file descriptors.
2) To replace the entire script with a new program (i.e. a wrapper script
   that has done all of its setup and is now gracefully retiring).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]