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
can't redirect stderr in bash lumix Shell Programming and Scripting 3 12-16-2007 01:28 AM
how to redirect stderr from top with csh umen Shell Programming and Scripting 2 02-22-2007 10:19 PM
how can i redirect stderr to file in Make? umen Shell Programming and Scripting 0 02-15-2007 01:04 AM
redirect stderr and/or stdout to /dev/null from command line knc9233 UNIX for Dummies Questions & Answers 1 01-25-2007 09:24 AM
Redirect stdout and stderr zcurtis Shell Programming and Scripting 8 09-02-2002 03:13 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 03-07-2006
Registered User
 

Join Date: Feb 2006
Posts: 25
redirect stderr to dev/null in bash env.

Working in a bash environment, in the following example, how do I direct the error message that putting in an invalid flag (-j for example) would normally produce to dev/null?

while getopts "abcd" opt
do
case "$opt" in
i) a etc ;;
r) b etc ;;
f) c etc ;;
v) d etc ;;
\?) direct actual error message to dev/null

exit 1 ;;
esac
done
Reply With Quote
Forum Sponsor
  #2  
Old 03-07-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,698
Quote:
Originally Posted by Sniper Pixie
Working in a bash environment, in the following example, how do I direct the error message that putting in an invalid flag (-j for example) would normally produce to dev/null?

while getopts "abcd" opt
do
case "$opt" in
i) a etc ;;
r) b etc ;;
f) c etc ;;
v) d etc ;;
\?) direct actual error message to dev/null

exit 1 ;;
esac
done
Code:
while getopts "abcd" opt
do
    case "$opt" in
      i) a etc ;;
      r) b etc ;;
      f) c etc ;;
      v) d etc ;;
      *) exit 1 ;;
    esac
done
Just exit.
Reply With Quote
  #3  
Old 03-07-2006
Registered User
 

Join Date: Feb 2006
Posts: 25
That doesn't work. It still outputs that -j is an invalid option
Reply With Quote
  #4  
Old 03-07-2006
Technorati Master
 

Join Date: Mar 2005
Location: Large scale systems...
Posts: 2,610
if you are so particular about the error messages from bash...
then this would do..

Code:
bash <yourscript> 2>/dev/null
Reply With Quote
  #5  
Old 03-07-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,698
Playing around...

Code:
while getopts "abcd" opt
do
    case "$opt" in
      i) a etc ;;
      r) b etc ;;
      f) c etc ;;
      v) d etc ;;
      \?) echo "$opt" 2>/dev/null ; exit 1 ;;
    esac
done
Reply With Quote
  #6  
Old 03-07-2006
vino's Avatar
Supporter (in vino veritas)
 

Join Date: Feb 2005
Location: Bangalore, India
Posts: 2,698
Else see this link - . Handling Command Line Arguments
Reply With Quote
  #7  
Old 03-07-2006
Registered User
 

Join Date: Feb 2006
Posts: 25
I'm afraid neither of those two solutions work. Both still print the error message, with the added bonus of yours producing a question mark as well, Vino.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 10:30 PM.


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

Content Relevant URLs by vBSEO 3.2.0