redirect stderr to dev/null in bash env.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting redirect stderr to dev/null in bash env.
# 8  
Old 03-07-2006
Okie dokie.. this should do the work

Code:
[/tmp]$ cat sniper.sh 
#! /bin/sh

while getopts "abcd" opt 2>/dev/null
do
    case "$opt" in
      a) echo "I" ;;
      b) echo "B" ;;
      *) exit 1 ;;
    esac
done
[/tmp]$ ./sniper.sh -b
B
[/tmp]$ echo $?
0
[/tmp]$ ./sniper.sh -j
[/tmp]$ echo $?
1
[/tmp]$

Cheers'

Last edited by vino; 03-07-2006 at 08:59 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Redirect string from bash stderr to user stdin

Hi there, I need to execute a command in the bash. The program prints some standard (output and) error and then wants the user to choose one of several options and type the according input. I am trying to solve this issue in a bash script but also running into some circular dependency. How can I... (7 Replies)
Discussion started by: fredestet
7 Replies

2. UNIX for Dummies Questions & Answers

Redirect Standard Error to /dev/null is not working.

Hello. When I run a .ksh that contains the command below, and there is no file available in the source location the "FILE_NAME_*.CSV not found" error is still being displayed. FILEN=$(ssh ${SOURCE_SERV} "cd ${SOURCE_LOCATION} ;ls ${FILES}") 2> /dev/null. This is interfering with the rest... (4 Replies)
Discussion started by: jimbojames
4 Replies

3. Shell Programming and Scripting

redirect the audio output to /dev/null

I'm using an text-to-speech synthesis in a script, and I need to redirect it's output to /dev/null how can I do that ? And how to redirect the stream to his normal output then (sound card ) ? thankx (2 Replies)
Discussion started by: firelink
2 Replies

4. Shell Programming and Scripting

[Solved] Stdout stderr to /dev/null

Sorry for my ignorance... but... I've a script with some output redirect to /dev/null, example: fsck.ext3 -a /dev/sdb1 1>/dev/null 2>/dev/null How can I simplify this redirect ? (1 & 2) thanks (3 Replies)
Discussion started by: ionral
3 Replies

5. Shell Programming and Scripting

Redirecting standard out to /dev/null goes to file "/dev/null" instead

I apologize if this question has been answered else where or is too elementary. I ran across a KSH script (long unimportant story) that does this: if ; then CAS_SRC_LOG="/var/log/cas_src.log 2>&1" else CAS_SRC_LOG="/dev/null 2>&1" fithen does this: /usr/bin/echo "heartbeat:... (5 Replies)
Discussion started by: jbmorrisonjr
5 Replies

6. UNIX for Dummies Questions & Answers

/dev/null 2>&1 Versus /dev/null 2>1

How are these two different? They both prevent output and error from being displayed. I don't see the use of the "&" echo "hello" > /dev/null 2>&1 echo "hello" > /dev/null 2>1 (3 Replies)
Discussion started by: glev2005
3 Replies

7. Shell Programming and Scripting

ssh, bash, and /dev/stderr: no such device

Hello, When I run the following program: ssh 192.168.1.4 bash -l <<EOF > echo foo >/dev/stderr > EOF I get the following confusing error. bash: line 1: /dev/stderr: No such device or address Does anyone know why and how to fix it? I'm capturing stdout in a variable, but I... (2 Replies)
Discussion started by: brsett
2 Replies

8. Shell Programming and Scripting

How to redirect the import log to /dev/null?

Hi i am running oracle database import through a script and script scans the import log to see if there are any errors. Now the porblem is that when i run the script the import log appears on the screen even if i direct the output of import to /dev/null. imp "'/ as sysdba'"... (5 Replies)
Discussion started by: vinoo128
5 Replies

9. Shell Programming and Scripting

can't redirect stderr in bash

Consider: #!/bin/sh #this is a shell script in sh (bourne) grep missingfile 2>errout.txt It works from the command line, but keeps producing errors from the script. So how do I redirect in a bash shell...or bourne? (3 Replies)
Discussion started by: lumix
3 Replies

10. UNIX for Dummies Questions & Answers

redirect stderr and/or stdout to /dev/null from command line

Is it possible to redirect errors at the command line when you run the script such as bash scriptname & 2>/dev/null? (1 Reply)
Discussion started by: knc9233
1 Replies
Login or Register to Ask a Question
APS2FILE(1)						    BSD General Commands Manual 					       APS2FILE(1)

NAME
aps2file -- printing to a file via apsfilter SYNOPSIS
aps2file [-D] [-Pqueue] [-Zoptions] [-ooutput] [input] aps2file [-h] DESCRIPTION
With aps2file you can direct the printer data generated by apsfilter(1) into an arbitrary file without the use of a spooler. OPTIONS
-h show help screen -D enable debug mode -Pqueue select a printer queue (different from the default one) -Zoptions use apsfilter command line options (comma-separated list) -ooutput direct data stream to output (default: stdout) input read data from input (default: stdin) Unlike printing with lpr(1), you can only use one input file at a time. Using aps2file is also the recommended way to create a debugging log of a failed printing attempt. If you include the -D flag, the apsfilter shell script will log every command and print it to stderr. To save the output for inclusion into a bug report, you should therefore use a command of the sort aps2file -D -o /dev/null [-P...] [-Z...] [input] 2> log.txt NOTES
aps2file only works correctly with entries in /etc/printcap that have been created by /usr/share/apsfilter/SETUP. FILES
/etc/printcap printer capability data base /usr/share/apsfilter/bin/apsfilter apsfilter script SEE ALSO
apsfilter(1), apsfilter-bug(1), apspreview(1), apsfilterrc(5), printcap(5) BUGS
See apsfilter software center - http://www.apsfilter.org/ - for new versions, bugfixes and known bugs. Please use the new tool apsfilter-bug(1) to release bug- or problem reports. It automatically presents you a form in an editor window which asks you some standard questions. If you save and quit the editor session, then this report is sent automatically via e-mail to the proper apsfilter mailinglist. If apsfilter fails to print something or prints it in a way you wouldn't expect and you want to report an apsfilter error then please save the debugging output of one print session using the new aps2file(1) utility by typing aps2file -D -Z options file > /dev/null 2> file.debug and including the debugging output in the file file.debug into the edit session of the apsfilter-bug utility, so that it is included into the mail to the apsfilter mailinglist. Please note that you need to run /bin/sh (Bourne Shell), bash or a compatible shell, so that the above mentioned output redirection works. Under C-shell (/bin/csh) or tcsh it would't work. If you don't know, then simply make sure you use the Bournce shell by typing /bin/sh or bash, then you should have no problems with redirection of stdout and stderr (> /dev/null 2> file.debug). DOCUMENTATION
See official apsfilter homepage http://www.apsfilter.org/handbook.html Apsfilter Handbook including the Frequently Asked Questions (FAQ) USER FORUM
Please send questions to the official apsfilter help channel apsfilter-help@apsfilter.org. The above section BUGS and the file HOWTO-BUGREPORTS tells you how to report bugs. If you want to know how to troubleshoot your apsfilter installation, please read the manpage aps2file(1) and apsfilter-bug(1) as well as the Apsfilter Handbook carefully. HISTORY
The aps2file manpage has been written by Michael LoBin <phallobst@web.de> and first appeared in apsfilter V 7.1.0. BSD
Dec 19, 2001 BSD