Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - General
User Name
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.


  Search this Thread
Old 02-12-2003, 07:45 PM   #1
Registered: Oct 2002
Location: USA, IL
Distribution: Debian/Gentoo/Slack
Posts: 215

Rep: Reputation: 30
File descriptors odd question

Hello all,

I'm reading a book on some interesting linux hacks and came across one that I'm slightly stumped on. I know about file descriptors 0, 1, and 2 (input, output, error) and how you can direct them to go down the same stream like so: command 2>&1 | ..... or var=`command 2>$1` but where I'm getting a bit confused is when they swap the descriptors using the mostly unused 3-9 FDs like so:

command 3>&2 2>&1 1>&3 | ....

Why would I want to swap file descriptors in the first place? Any practical examples? Also it mentions closing the extraneous FDs like so: 3>&~ , is this the correct format? doesn't ~ stand for the home directory? If anyone can shed some light on this I'd appreciate it.

Old 02-13-2003, 06:13 AM   #2
Senior Member
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 47
Chapter 16 of the Advanced bash scripting guide explains it pretty well I think.

And the syntax for closing a file descriptor is 3>&-
Old 02-13-2003, 11:21 AM   #3
Registered: Oct 2002
Location: USA, IL
Distribution: Debian/Gentoo/Slack
Posts: 215

Original Poster
Rep: Reputation: 30
Well that would make a bit more sense to me


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
Increasing File Descriptors Geoffrey_Firmin Slackware 5 04-21-2008 10:48 AM
Socket File Descriptors for a process MadCoder77 Linux - Networking 0 05-26-2005 05:19 PM
file descriptors node047 Linux - Newbie 1 03-29-2005 06:47 AM
unix file descriptors versus c FILE pointers nodger Programming 9 11-25-2004 08:02 AM
File Descriptors - How to raise the limit? xmdms Linux - General 3 07-15-2004 01:57 AM > Forums > Linux Forums > Linux - General

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

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