LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 03-15-2007, 02:28 AM   #1
nikhil_rs_maheshwari
LQ Newbie
 
Registered: Feb 2006
Posts: 11
Blog Entries: 1

Rep: Reputation: 0
Confusion about Output redirction


HI,


Could anyone please give me insigt into output redirection .

I execute followu=ing commands

Scenario :

************
$(cat xxx 2>&1)> test

As i understand from the syntax if command errors out then it will place output in the same place where it would had put normal output.

**********
$(cat xxx 3>&2 2>&1 1>&3) > test

But here i m really confused with file descriptor 3.

Could anyone plz explain it ?.........


Looking forward to hear from Linux community.

Thanx well in advance.
 
Old 03-15-2007, 04:18 AM   #2
budword
Member
 
Registered: Apr 2003
Location: Wisconsin
Distribution: Switched to regualr Ubuntu, because I don't like KDE4, at all. Looks like vista on crack.....
Posts: 675

Rep: Reputation: 31
Output redirection uses the pipe charactor | which lives above the backslash which is above the return key. (IF that makes sense, it's late and I'm tired.) The > writes the output of the previous command to a file. I'm not sure what using > multiple times in the same command when you don't mean to write multiple files will do. Probably just doesn't work.

Hope that helps....

David
 
Old 03-15-2007, 04:21 AM   #3
Nathanael
Member
 
Registered: May 2004
Location: Karlsruhe, Germany
Distribution: debian, gentoo, os x (darwin), ubuntu
Posts: 940

Rep: Reputation: 32
this basically turns 1 and 2 arround: now only error messages are in 'test' and no other output
in bash you have 9 descriptors (and google-ing for descriptors and bash usually gets you some nice tutorials)
1 is reserved for stdout
2 is reserved for stderr
3-9 are not reserved

after (cat xxx 3>&2 2>&1 1>&3) your have 1 = stderr and 2 = stdout, but only outside of the brackets.
 
Old 03-15-2007, 04:24 AM   #4
Nathanael
Member
 
Registered: May 2004
Location: Karlsruhe, Germany
Distribution: debian, gentoo, os x (darwin), ubuntu
Posts: 940

Rep: Reputation: 32
Quote:
Originally Posted by budword
Output redirection uses the pipe charactor | which lives above the backslash which is above the return key. (IF that makes sense, it's late and I'm tired.) The > writes the output of the previous command to a file. I'm not sure what using > multiple times in the same command when you don't mean to write multiple files will do. Probably just doesn't work.

Hope that helps....

David
2>&1 is about descriptors, not files
| is a pipe and not output redirection
different countries have different keyboards, so generallizing that one key is obove another does not always make sense.
 
Old 03-15-2007, 04:56 AM   #5
nikhil_rs_maheshwari
LQ Newbie
 
Registered: Feb 2006
Posts: 11
Blog Entries: 1

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Nathanael
this basically turns 1 and 2 arround: now only error messages are in 'test' and no other output
in bash you have 9 descriptors (and google-ing for descriptors and bash usually gets you some nice tutorials)
1 is reserved for stdout
2 is reserved for stderr
3-9 are not reserved

after (cat xxx 3>&2 2>&1 1>&3) your have 1 = stderr and 2 = stdout, but only outside of the brackets.

Hi Nathanael,

Thanx alot for ur valuable inputs.

correct me if i m wrong in saying that
1.when we execute command like ..file 2>&1 , it does mean report output & error(if any) in same file .

2.Now here, let me break entire expression in three parts

3>&2 -- Does it mean output value to be placed where error vals r placed?..
2>&1 -- Does it mean error vals to be place where stdout vals r placed?..
1>&3 -- Does it mean stdout vals r placed where out vals r placed i.e. in turn output to be placed where errors are placed ?..

3. What is the significance of File Descriptors i.e. 3-9 in normal sense ?.
How do they act as out/in/error descriptor ?..
or their behaviour depends on the context in which they have been used?..

I may sound sound naive in asking aforesaid questions, but i need clarification.

Looking forward to hear from you.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
grep output on stdout and grep output to file don't match xnomad Linux - General 3 01-13-2007 04:56 AM
g++ == confusion slantoflight Programming 4 02-20-2006 01:19 PM
Via AC'97 5.1 Optical Output or Audigy 4.1 Output Nza Fedora 3 06-01-2004 07:49 AM
the sound gives output when using mic but no output when run a music file medo Debian 0 04-19-2004 07:17 PM
Some confusion about RH 7.3 psyklops Linux - Distributions 2 05-08-2002 03:08 PM


All times are GMT -5. The time now is 02:04 AM.

Main Menu
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