LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-11-2004, 12:52 AM   #1
blackzone
Member
 
Registered: Jun 2004
Posts: 256

Rep: Reputation: 30
shell short question(stdout, stderr)


I know:
command >/dev/null //output not shown
command 1>/dev/null //standard output not shown
command 2>/dev/null //standard error not shown
command 2&> /dev/null //standard output + error not shown

how about:
command 1>/dev/null 2>&1

it sends stdout to /dev/null and??
 
Old 11-11-2004, 02:47 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
how about:
command 1>/dev/null 2>&1

it sends stdout to /dev/null and??
...sends stdandard error (stderr) to the same place where standard input (stdin) is going.

Note that the order matters: "command 2>&1 >/dev/null" doesn't work because stderr is first redirected to the same place as stdout, after that, stdout is redirected to /dev/null.

In the case of redirecting to /dev/null it does not matter much which form you use, but when you want to redirect both stdout and stderr to a single file, this doesn't work: "command >my_file.txt 2>my_file.txt"
but this does: "command >my_file.txt 2>&1"

These forms are exactly the same, only the syntax is different:

command >some_file 2>&1
command 1>some_file 2>&1
command &> some_file
command >& some_file

And I suppose the one you mentioned ("command 2&> some_file") belongs to this list as well.
 
Old 11-11-2004, 03:12 AM   #3
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 53
Quote:
...sends stdandard error (stderr) to the same place where standard input (stdin) is going.
WRONG!!!
2>&1 redirects stderr to stdout, error messages get sent to the same place as standard output.

this is why
Code:
command 1>/dev/null 2>&1
is the same with
Code:
command &>/dev/null
.
Both redirect stderr and stdout to /dev/null
 
Old 11-11-2004, 07:39 AM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
It redirects stderr to stdout which is redirected to /dev/null. The effect is the same as
2&>/dev/null.
 
Old 11-11-2004, 09:01 AM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
Originally posted by perfect_circle
WRONG!!!
2>&1 redirects stderr to stdout, error messages get sent to the same place as standard output.
TRUE,
I said by mistake: "standard input(stdin)", where it should have been: "standard output (stdout).

Thanks for correcting that.
 
  


Reply



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
TCSH: redirect stdout and stderr seperately ugenn Linux - General 3 02-07-2016 03:23 PM
redirecting stdout and stderr to a file Avatar33 Programming 4 03-12-2005 07:55 AM
Reopen the stdout and stderr rahul_kulkarni Programming 3 02-21-2005 06:55 AM
Not your regular GRUB question - just a short question for a fried MBR!! ziphem Linux - General 3 01-31-2005 01:51 PM
question about printing to stderr in C purpleburple Programming 2 10-30-2002 01:37 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:12 AM.

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
Open Source Consulting | Domain Registration