The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
UNIX newbie NEWBIE question! Hanamachi UNIX for Dummies Questions & Answers 3 09-14-2006 07:23 AM
newbie question xzyan UNIX for Dummies Questions & Answers 6 08-08-2006 07:22 AM
Newbie question peeyush_23 Shell Programming and Scripting 9 02-18-2005 02:39 PM
Newbie Question... flopper UNIX for Dummies Questions & Answers 4 11-27-2001 12:51 PM
newbie question ninja UNIX for Dummies Questions & Answers 3 07-11-2001 01:34 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-08-2006
Registered User
 

Join Date: Mar 2006
Posts: 89
newbie question

hey all, I have repeatedly seen scripts containing the following syntax,

grep "hello" $myfile >> $log 2>&1

can anyone explain exactly what "2>&1" mean? THANK YOU
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 08-08-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,643
Care to read the man pages ? See the section REDIRECTION under man sh.
Reply With Quote
  #3 (permalink)  
Old 08-08-2006
Registered User
 

Join Date: Aug 2006
Posts: 18
while i am waiting other to help on my question, let me explain it to you !!

grep "hello" $myfile >> $log -----> all standard output will go into $log, except error which will output to your screen.

for this reason,we use 2>&1 ----> so that (2)=all error will go into (1)=standard output which you have already define as $log

so all output including error message wll all go into $log

Anyway man page will explain in more detail....
Reply With Quote
  #4 (permalink)  
Old 08-08-2006
Dhruva's Avatar
Registered User
 

Join Date: Mar 2006
Location: India
Posts: 241
If you find man page not very interesting.These two links will give you idea about file descriptors (2>...>&1)

link 1

link 2
Reply With Quote
  #5 (permalink)  
Old 08-08-2006
Registered User
 

Join Date: Aug 2006
Posts: 69
In unix 1 is defaut file descriptor for stdout and 2 is default file descriptor for stderr. So when you try redirecting on any of them you will redirect the stderr or stdout to a file or /dev/null.

regards
Apoorva Kumar
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:55 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0