Main Page | Report this Page
Linux Forum Index  »  Linux Miscellaneous Topics 2  »  question about file descriptor...
Page 1 of 1    

question about file descriptor...

Author Message
fasf...
Posted: Sat Oct 24, 2009 4:52 am
Guest
I haven't a clear idea about file descriptor......A file descriptor is
an integer:
0-standard input
1-standard output
2-standard error
Can i have more file descriptors?How can be used?
I can duplicate a file descriptor with <& or >&: what means 1<&2 ?I
think that standard input (1) displays also standard error (2)...is
this correct?
Thanks
 
Sam...
Posted: Sat Oct 24, 2009 1:41 pm
Guest
fasf writes:

Quote:
I haven't a clear idea about file descriptor......A file descriptor is
an integer:
0-standard input
1-standard output
2-standard error
Can i have more file descriptors?

Certainly. Each time you open a file you get a new file descriptor for it.

Quote:
How can be used?

Open a file.

Quote:
I can duplicate a file descriptor with <& or >&: what means 1<&2 ?I

Ah, you're talking about shell redirection directives, and not file
descriptors per se.

"1<&2" means to duplicate file descriptor 2 to file descriptor 1.
Whatever's currently open on file descriptor 1 is closed and replaced so
that both file descriptor 2 and file descriptor 1 now refer to the same
file.

"1<&2" means the same thing as "1>&2". Duplicating a file descriptor is the
same operation whether or not the file descriptor is open for input or
output. So, "1<&2" is actually misleading; it's more pedantically proper to
write "1>&2", since file descriptor 2 is always open for output.

When multiple file descriptor refer to the same underlying file, and they
are open for output, both of them should really be open for appending,
otherwise the results will be pretty much useless as they'll write all over
each other. Therefore, a fairly common thing to see is:

command 2>>command.output 1>&2

Both the standard output and standard error are appended to command.output.

Quote:
think that standard input (1) displays also standard error (2)...is
this correct?

File descriptor 1 is standard output, not standard input.

As far as additional file descriptor goes:

command 3>command.x

"command.x" is open for output on file descriptor 3. Of course, "command"
needs to be explicitly aware that it has something open for output on file
descriptor 3.
 
fasf...
Posted: Wed Oct 28, 2009 10:25 am
Guest
Thanks for your reply...

Quote:
Can i have more file descriptors?

Certainly. Each time you open a file you get a new file descriptor for it..

                                  How can be used?

Open a file.

If i open a file, i have a new file descriptor like 3,4,ecc..?

Quote:
command 2>>command.output 1>&2

What does ">>" mean?


Thanks
 
Sam...
Posted: Wed Oct 28, 2009 3:44 pm
Guest
fasf writes:

Quote:
Thanks for your reply...

Can i have more file descriptors?

Certainly. Each time you open a file you get a new file descriptor for it.

                                  How can be used?

Open a file.

If i open a file, i have a new file descriptor like 3,4,ecc..?

Correct.

Quote:

command 2>>command.output 1>&2

What does ">>" mean?

Append to an existing file. ">" overwrites any existing file with the
output. ">>" preserves any existing file, and adds new output at its end. If
the file does not exist, ">" and ">>" does the same thing.
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Tue Dec 15, 2009 12:50 am