The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 4 03-28-2009 04:10 PM
newbie question xzyan UNIX for Dummies Questions & Answers 6 08-08-2006 10:22 AM
Newbie question peeyush_23 Shell Programming and Scripting 9 02-18-2005 06:39 PM
Newbie Question... flopper UNIX for Dummies Questions & Answers 4 11-27-2001 04:51 PM
newbie question ninja UNIX for Dummies Questions & Answers 3 07-11-2001 04:34 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-08-2006
mpang_ mpang_ is offline
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
  #2 (permalink)  
Old 08-08-2006
vino's Avatar
vino vino is offline Forum Staff  
Supporter (in vino veritas)
  
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,796
Care to read the man pages ? See the section REDIRECTION under man sh.
  #3 (permalink)  
Old 08-08-2006
3Gmobile 3Gmobile is offline
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....
  #4 (permalink)  
Old 08-08-2006
Dhruva's Avatar
Dhruva Dhruva is offline
Registered User
  
 

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

link 1

link 2
  #5 (permalink)  
Old 08-08-2006
apoorvasharma80 apoorvasharma80 is offline
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
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 04:07 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0