LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   /dev/fd question (https://www.linuxquestions.org/questions/linux-general-1/dev-fd-question-770342/)

urban.yoga.journeys 11-19-2009 08:34 PM

/dev/fd question
 
what exactly is going on in this piece of code? what is the role of /dev/fd? i know that /dev/fd/0 is somehow linked to standard input, but that's the extent of my knowledge

Code:

cat header.txt /dev/fd/0 footer.txt

GrapefruiTgirl 11-19-2009 09:56 PM

http://www.informit.com/articles/art...eqNum=15&rll=1

The above link explains /dev/fd. Generally /dev/fd/ has an entry for stdin, stdout, and stderr. stdin is /dev/fd/0.

Therefore, your code cats a file called header.txt, followed by stdin, followed by the file footer.txt, one after the other. It is the equivalent to:

cat header.txt - footer.txt

where the dash in the middle signifies stdin.

Sasha

urban.yoga.journeys 11-19-2009 11:54 PM

the explanation in the link is almost exactly the same as the one given in the manual i'm reading. i'm afraid i still don't understand it.

urban.yoga.journeys 11-20-2009 01:48 AM

ok i think i have the /dev/fd/0 figured out. i have another question, still related to re-direction. what's the difference with:

Code:

exec 7<&0
and

Code:

exec 7>&0


All times are GMT -5. The time now is 08:24 AM.