How to suppress error messages in script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to suppress error messages in script
# 1  
Old 01-16-2007
How to suppress error messages in script

I am getting the following upon cat a file which is not present in directory.
"cat: cannot open test1.txt"
I need to process files and I want that this message should be suppressed. thx
# 2  
Old 01-16-2007
When you run your script, run it as '/path/to/script 2>/dev/null'. This means that all the stuff that would be written to standard error is to be redirected to /dev/null.
# 3  
Old 01-16-2007
Could please explain more, I am new to scripting so when you say "run it as '/path/to/script 2>/dev/null' "

this means I should add this line in my script?
# 4  
Old 01-16-2007
No, it means when you run your script, add the exact text below right after the name of the script, before you press 'enter' on the command line.
Code:
2>/dev/null

If your script is named "x.sh" , then when you run it, type "x.sh 2>/dev/null".
# 5  
Old 01-17-2007
Quote:
Originally Posted by helper2007
Could please explain more, I am new to scripting so when you say "run it as '/path/to/script 2>/dev/null' "

this means I should add this line in my script?
Have look at this for more explanation: https://www.unix.com/shell-programming-and-scripting/34011-meaning-dev-null-2-1-a.html
# 6  
Old 01-17-2007
Quote:
Originally Posted by helper2007
I am getting the following upon cat a file which is not present in directory.
"cat: cannot open test1.txt"
I need to process files and I want that this message should be suppressed. thx
... or just close fd 2:

cat test1.txt 2>&-


Regards
Dimitre
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Tcsh: How to suppress error messages.

Hallo, I wrote some script: 95% of the script's output consists of error messages like "mkdir: cannot create directory ‘final': File exists Exit 1" and "rm: No match. Exit 1". These messages are not harmful at all, but they make the output almost unreadable. How can I get rid of... (5 Replies)
Discussion started by: DanielDD
5 Replies

2. Shell Programming and Scripting

How to suppress error in following command?

I have a file containing data in multiple columns. The colums are seperated by pipe (|). I need to extract information as below: myfile_20130929_781;10;100.00 where myfile.txt is the file name. 10 is the number of records in the file starting with 120 and 100.00 is the sum of 26th field of... (16 Replies)
Discussion started by: angshuman
16 Replies

3. Shell Programming and Scripting

Suppress Error Message

How can I suppress a error message being given by awk command in bash shell? (2 Replies)
Discussion started by: Prachi Gupta
2 Replies

4. UNIX for Dummies Questions & Answers

suppress RCS messages

ci filename This command displays a message. I don't want it to. How can I keep RCS from doing so? (5 Replies)
Discussion started by: robin_simple
5 Replies

5. UNIX for Dummies Questions & Answers

pine email tool suppress prompt to save read messages

Could somebody please advise about how to configure pine/alpine so that on exit it doesn't prompt me to save read messages? Thanks (3 Replies)
Discussion started by: LeoKSimon
3 Replies

6. Shell Programming and Scripting

How to suppress the error while copying the file

HI , I am tryin to copying multiple files from some dir. If the files are not present. It should not throw error in the screen. HOw to do that . Please help (4 Replies)
Discussion started by: arukuku
4 Replies

7. Shell Programming and Scripting

Suppress error message in shell script

Hi All this is a simple script #! /bin/bash FileCnt=`ls -lrt $DIR/* | wc -l` echo $FileCnt how could i escape the error msg if there are no files in $DIR ls: /home/sayantan/test/files/cnt/*: No such file or directory 0 Looking forward for a quick reply Regards, Newbie... (3 Replies)
Discussion started by: newbie07
3 Replies

8. Shell Programming and Scripting

Suppress error message in unzip

I'm creating a bsh shell to unzip a file from one directory into another. The directory that holds the zip files has zip files constantly being added to it, so I am testing it before it does the unzip and more. Right now my code looks like this: unzip -tq $ZIP_PATH/$ZIP_NAME >/dev/null if ... (5 Replies)
Discussion started by: skwyer
5 Replies
Login or Register to Ask a Question