Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 02-17-2013, 10:25 AM   #1
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:

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:

#Duplicating and closing (in case word expands to -):
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?

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 12:19 PM. Reason: Found out the answer.
Old 02-17-2013, 03: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: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960
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 03:20 PM.


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 02:21 AM
[bash] sudo: preserve non-std file descriptors DieZwiebel Linux - Software 1 02-27-2012 09:41 AM
[SOLVED] Don't Understand Duplicate File Descriptors in Bash dcparris Linux - Server 3 12-28-2011 11:27 PM
Closing file descriptors nikin Linux - Newbie 2 06-05-2008 04:16 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:35 AM.

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