help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Why 'exec' has to be used in with fd<>filename? And the


From: Ken Irving
Subject: Re: [Help-bash] Why 'exec' has to be used in with fd<>filename? And the difference between <> and >>?
Date: Wed, 12 Feb 2014 09:58:10 -0900
User-agent: Mutt/1.5.20 (2009-06-14)

On Wed, Feb 12, 2014 at 08:36:04AM -0500, Greg Wooledge wrote:
> On Tue, Feb 11, 2014 at 05:28:59PM -0600, Peng Yu wrote:
> > exec fd<>fileName
> 
> > In the above document, I don't see 'exec' should be used. Where is
> > this documented? Thanks.
> 
> As Chet said, exec is used when you want the shell to open or close
> a file descriptor.  Think of it as bash's builtin version of open()
> and close() with a silly name inherited from the Bourne shell.

Practically, opening a filehandle using exec allows a file to be read or
written incrementally in a script, e.g., perhaps reading and processing
some lines in one place, doing other stuff, then reading subsequent
lines as needed.  Pretty much like reading/writing stdin and stdout,
but you're not limited to just one of each.

In contrast, regular redirection happens all at once, so if you want
to read a few lines, do some processing, then later read more lines,
you'd need to read the file twice, skipping the first lines.

(I only recently started using exec in this way, and am working to
understand it myself.)

Ken



reply via email to

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