LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   File descriptors odd question (https://www.linuxquestions.org/questions/linux-general-1/file-descriptors-odd-question-45136/)

ferreter 02-12-2003 06:45 PM

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.

Thanks!

Mik 02-13-2003 05:13 AM

Chapter 16 of the Advanced bash scripting guide explains it pretty well I think.

And the syntax for closing a file descriptor is 3>&-

ferreter 02-13-2003 10:21 AM

Well that would make a bit more sense to me :D


All times are GMT -5. The time now is 01:19 AM.