LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 09-12-2006, 02:48 AM   #1
nickleus
Member
 
Registered: Nov 2004
Location: Noreg
Distribution: ubuntu
Posts: 107

Rep: Reputation: 15
what does "standard error was duplicated as standard output" mean?


here:
http://www.gnu.org/software/bash/man...ref.html#SEC37
it says:
Code:
ls 2>&1 > dirlist
Quote:
directs only the standard output to file dirlist, because the standard error was duplicated as standard output before the standard output was redirected to dirlist.
i know that in this example the standard output is sent to the file dirlist and the standard error is written to the screen. but what does it really mean that "the standard error was duplicated as standard output"?
 
Old 09-12-2006, 03:16 AM   #2
Samotnik
Member
 
Registered: Jun 2006
Location: Belarus
Distribution: Debian GNU/Linux testing/unstable
Posts: 471

Rep: Reputation: 40
It means that error messages was send to standard error and standard output simultaneosly
 
Old 09-14-2006, 02:50 PM   #3
nickleus
Member
 
Registered: Nov 2004
Location: Noreg
Distribution: ubuntu
Posts: 107

Original Poster
Rep: Reputation: 15
ok, so that means that standard error messages were printed to the screen first (or at least directed to the screen, in the case that there were any errors), then the standard output (if there was any) would be directed to the file? maybe this is a dumb question, but can you ever get standard errors and output at the same time? or is it always one or the other?
 
Old 09-14-2006, 03:44 PM   #4
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Quote:
ls 2>&1 > dirlist
Let's break it down.

"2" is "stderr" a.k.a. "standard error"
"1" is "stdout" a.k.a. "standard output"
">" can be thought of as "sent to"
"&" can be thought of as "the same place as"

By default, "1" is normally sent to your screen. So is "2".

To send "standard output" to a file named "dirlist", you would do this: 1>dirlist Read this as:
Code:
"standard output" + "sent to" + "dirlist"
You can leave off the leading "1" and it means the same thing, since "1" is assumed if nothing is specified. Therefore, >dirlist is just a shorthand way of writing 1>dirlist

Looking at the text string "2>&1", this can be read as:
Code:
"standard error" + "sent to" + "the same place as" + "standard output"
Now, order is important. ls 2>&1 >dirlist is not the same as ls >dirlist 2>&1
The first case directs 2 into the same place as 1, and then directs 1 into dirlist. But at the time 2 was sent to the same place as 1, 1 was going to it's default. Your screen. But 2 goes to your screen by default too! So that operation didn't really do anything.

In the second case, 1 was directed to dirlist first, and then 2 was directed to the same place as 1. So 2 would then go to dirlist also.

So to capture both stdout and stderr to a file, first direct 1 to the file, then direct 2 to the same place as 1. e.g., ls >dirlist 2>&1
 
Old 09-15-2006, 06:14 AM   #5
nickleus
Member
 
Registered: Nov 2004
Location: Noreg
Distribution: ubuntu
Posts: 107

Original Poster
Rep: Reputation: 15
ok. got it. thank you very much haertig!
what i didn't see at first was the second ">":
Code:
ls 2>&1 >dirlist
is the same as:
Code:
ls 2>&1 1>dirlist
totally clear now =)
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl: warning: Falling back to the standard locale ("C"). walterbyrd Debian 11 05-14-2009 08:50 AM
Where "standard system include directory" is defined? (gcc) kaz2100 Programming 8 07-23-2006 08:22 AM
LXer: VectorLinux 5.1 "Standard" Live CD RC3 has been released LXer Syndicated Linux News 0 04-21-2006 07:03 PM
Howto disable "Graphical Login" or "Standard Login?" the_gripmaster Red Hat 1 07-08-2004 02:55 PM
So what ethernet card is supported "as standard" by 2.2.19 kernel?... Simon W Linux - Networking 2 02-14-2002 01:25 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

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