bug-bash
[Top][All Lists]
Advanced

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

Redirection - Duplicating File Descriptors


From: Gingko
Subject: Redirection - Duplicating File Descriptors
Date: Sun, 05 Aug 2001 10:01:00 GMT

Hello,

I would like to ask a question about a specific feature of  'bash' :

Both the 'man' pages and the reference manual describe the following in the 
'redirection'
section :

------------------------------------------------------------------------------------------------
----
Duplicating File Descriptors
The redirection operator

[n]<&word

is used to duplicate input file descriptors. If word expands to one or more 
digits, the file
descriptor denoted by n is made to be a copy of that file descriptor. If the 
digits in word do
not specify a file descriptor open for input, a redirection error occurs. If 
word evaluates
to -, file descriptor n is closed. If n is not specified, the standard input 
(file descriptor 0)
is used.

The operator

[n]>&word

is used similarly to duplicate output file descriptors. If n is not specified, 
the standard
output (file descriptor 1) is used. If the digits in word do not specify a file 
descriptor open
for output, a redirection error occurs. As a special case, if n is omitted, and 
word does not
expand to one or more digits, the standard output and standard error are 
redirected as described
previously.
------------------------------------------------------------------------------------------------
----

Does somebody have a precise example of this ?

I more or less understand that on that way it is possible to redirect a file 
stream towards two
file descriptors, but whatever I try to type as "word" doesn't give consistant 
results to me.

Does it allow to, saying a trivial example, redirect the output of a 'ls' 
command to a file AND
leave it to the standard output at the same time ?

If yes, how would I type this on the command line ?

If not, is there a way to accomplish this in a pure 'bash' command form, 
without writing my own
(of course short, but...) C program for doing it ?
Is there a standard Unix/Linux command for that ?

I'm sorry if this is not the correct workgroup for this, but finding one is not 
very obvious.

Thank you very much in advance for your(s) answer(s).

Gilles Reeves.





reply via email to

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