LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 11-19-2009, 09:34 PM   #1
urban.yoga.journeys
Member
 
Registered: Jun 2008
Posts: 31

Rep: Reputation: 16
/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
 
Old 11-19-2009, 10:56 PM   #2
GrapefruiTgirl
Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
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
 
Old 11-20-2009, 12:54 AM   #3
urban.yoga.journeys
Member
 
Registered: Jun 2008
Posts: 31

Original Poster
Rep: Reputation: 16
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.
 
Old 11-20-2009, 02:48 AM   #4
urban.yoga.journeys
Member
 
Registered: Jun 2008
Posts: 31

Original Poster
Rep: Reputation: 16
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
 
  


Reply

Tags
input, io, output, redirection


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
pseudo terminals: /dev/ptmx <-> /dev/pts/ vs. /dev/ptyp <-> /dev/ttyp rtspitz Linux - Software 2 12-02-2011 03:07 PM
[SOLVED] wiping HDD using /dev/urandom versus /dev/zero, a theoretical question H_TeXMeX_H Linux - General 6 06-29-2009 07:55 AM
OpenSUSE x86_64 does not mount /dev/tape (or /dev/st0 or /dev/nst0) yankeeinga Linux - Newbie 6 08-21-2008 01:51 PM
using flash drive changes device /dev/sr0 to /dev/sr1 for mapping to /dev/pktcdvd/0? lugoteehalt Linux - Software 3 10-24-2007 11:27 AM
Clone with dd if=/dev/hda of=/dev/hdb question wrc1944 Linux - Hardware 2 11-28-2004 10:10 AM


All times are GMT -5. The time now is 05:16 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration