LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-17-2013, 11:25 AM   #1
moraxu
LQ Newbie
 
Registered: Dec 2012
Distribution: Ubuntu
Posts: 15

Rep: Reputation: Disabled
Significance of arrows symbols in duplicating/closing file descriptors under bash


I'm reading a book about Linux command line where author doesn't seem to follow the conventions in bash manual regarding arrows symbols used in redirection operations. Namely, he always uses left arrow < in duplicating and closing file descriptors regardless of whether the descriptors are input or output ones.

Here is an example:

Code:
exec 3<&0 4<&1 #shouldn't be 4>&1 ?
#...
exec 3<&- 4<&- #shouldn't be 4>&- ?
Bash man page is vague in this point, according to it, the duplicating/closing and moving file descriptors have the following syntaxes:

Code:
#Duplicating and closing (in case word expands to -):
[n]<&word 
[n]>&word
    
#Moving:
[n]<&digit-
[n]>&digit-
They are described to have different behaviour only if we don't explicitly supply the n. But when we do, does it mean that we can use these forms interchangeably?

EDIT:
OK, now I know that these forms are the same, they both use dup2(1, 4) system call to duplicate 1 fd.

Last edited by moraxu; 02-17-2013 at 01:19 PM. Reason: Found out the answer.
 
Old 02-17-2013, 04:09 PM   #2
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Yep. It doesn't matter which direction its pointing when you're closing an fd. It's not going to be useable after that anyway.

See here for an excellent tutorial on how file descriptors work:

redirections and file descriptors explained


PS: I wasn't aware that you could move/renumber them though. That's neat.

Last edited by David the H.; 02-17-2013 at 04:20 PM.
 
  


Reply


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing file descriptors before fork kev82 Programming 2 12-09-2012 03:21 AM
[bash] sudo: preserve non-std file descriptors DieZwiebel Linux - Software 1 02-27-2012 10:41 AM
[SOLVED] Don't Understand Duplicate File Descriptors in Bash dcparris Linux - Server 3 12-29-2011 12:27 AM
Closing file descriptors nikin Linux - Newbie 2 06-05-2008 05:16 AM


All times are GMT -5. The time now is 06:38 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration