LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-01-2004, 07:01 AM   #1
dominant
Member
 
Registered: Jan 2004
Posts: 409

Rep: Reputation: 30
2>&1 ?


Could anyone tell me what 2>&1 means?
 
Old 02-01-2004, 07:51 AM   #2
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
What it actually does is a little confusing. The result is easy to understand.

Those numbers are file descriptors that exist for bash by default. 1 is stdout the terminal. 2 is stderr where all errors are reported.

What this does is to write error messages to the same place regular output goes, combining both into one stream. For example when you run a job, you may want to keep the good out and also save any error messages all at the same time -- all in one file.
 
Old 02-01-2004, 07:52 AM   #3
jim mcnamara
Member
 
Registered: May 2002
Posts: 964

Rep: Reputation: 36
Technically, the & calls the dup() function.

You can look up dup in the manpages.
 
Old 02-01-2004, 07:53 AM   #4
mikshaw
LQ Addict
 
Registered: Dec 2003
Location: Maine, USA
Distribution: Slackware/SuSE/DSL
Posts: 1,320

Rep: Reputation: 45
It's a redirect.
2 represents stderr and 1 is stdout

Check out Bash-Prog-Intro-HOWTO for more info

again....i type so slowly.....
 
Old 02-01-2004, 08:04 AM   #5
dominant
Member
 
Registered: Jan 2004
Posts: 409

Original Poster
Rep: Reputation: 30
For example, i have seen the 2>&1 in scripts which are run through cron.

Then if an error occur then a console will open automatically reporting the error.

Am i right?
 
Old 02-01-2004, 08:50 AM   #6
delta9
Member
 
Registered: Dec 2003
Distribution: Gentoo
Posts: 66

Rep: Reputation: 15
Quote:
Originally posted by dominant
For example, i have seen the 2>&1 in scripts which are run through cron.

Then if an error occur then a console will open automatically reporting the error.

Am i right?
If you redirect stdout (standard output) to a file by using "./program 1>file" and you want the errormessages of the program to go to the same file you use "./program 1>file 2>&1"

If stdout is your screen then errormessages will go to the screen too when using 2>&1
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
zsnes && logitech dual action gamepad && dpad woes John5788 Linux - Games 5 10-29-2008 10:56 PM
(FreeBSD && Fedora Core 4 && Slackware 10.0) Filesystem Support taylor_venable *BSD 1 07-14-2005 03:24 PM
Japanese canna won't work : Warning: かな漢字変&am OrganicOrange84 Debian 3 06-30-2005 03:28 PM
Phục hồi dữ liệu bị mất???, cứ pollsite General 1 06-27-2005 01:39 PM
SuSE9 && Samba && Win2k DaFrEQ Linux - Software 2 01-27-2004 08:45 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:34 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration