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: Chet Ramey
Subject: Re: [Help-bash] Why 'exec' has to be used in with fd<>filename? And the difference between <> and >>?
Date: Tue, 11 Feb 2014 21:08:28 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.3.0

On 2/11/14, 6:28 PM, Peng Yu wrote:
> Hi,
> 
> exec fd<>fileName
> 
> The example shown at
> http://bash.cyberciti.biz/guide/Opening_the_file_descriptors_for_reading_and_writing
> is easier to follow that what is in man bash.
> 
>    Opening File Descriptors for Reading and Writing
>        The redirection operator
> 
>               [n]<>word
> 
>        causes  the  file  whose name is the expansion of word to be
> opened for both reading
>        and writing on file descriptor n, or on file descriptor 0 if n
> is not specified.  If
>        the file does not exist, it is created.
> 
> In the above document, I don't see 'exec' should be used. Where is
> this documented? Thanks.

You use `exec' when you want the file descriptor to remain open in the
calling shell.

It's documented in a couple of places, but not in the redirection section
because it doesn't really have to do with the redirection itself.

In the `SIMPLE COMMAND EXPANSION' section, you find

"If  no  command  name  results,  redirections are performed, but do not
affect the current shell environment."

In the description of `exec', you find

"If command is not specified, any redirections take effect in the current
shell, and the return status is 0."

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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