Suppress error message in shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Suppress error message in shell script
# 1  
Old 12-31-2007
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
Happy New Year
# 2  
Old 12-31-2007
Use this:

Code:
FileCnt=`ls -lrt $DIR/* 2>/dev/null| wc -l`

# 3  
Old 12-31-2007
Code:
ls -lrt $DIR/* 2> /dev/null | wc -l`

# 4  
Old 12-31-2007
Thanks a lot
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash function to suppress warning message for specific text and display prompt

In the below bash function multiple variants are input and stored in a variable $variant, and each is written to an out file at c:/Users/cmccabe/Desktop/Python27/out.txt stored on a separate line. # enter variant phox2b() { printf "\n\n" printf "What is the id of the patient getting... (0 Replies)
Discussion started by: cmccabe
0 Replies

2. Shell Programming and Scripting

sed garbled error message in bash shell

Sed garbled error. Cannot determine why the sed command to insert a line at the beginning of a file will not work on declared variables. outfile='DAR.V2.2012115.1.CSV' testfile='totality_request.sql' header_prefix='DATA FILE' no_ext_file=`echo $outfile |sed 's/\(.*\)..../\1/'` ... (6 Replies)
Discussion started by: smenago
6 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. Shell Programming and Scripting

how to suppress the status of fork in shell script

When command is executed by forking, the console displays the status of that command. I want to suppress it.. how to do it ? Example: var1=`date` & echo "hello world"; output: hello world + Done var1=`date` I want to suppress the second line "+ Done var1=`date`". I... (10 Replies)
Discussion started by: Arun_Linux
10 Replies

5. Shell Programming and Scripting

Suppress a background message in Bash

I'm having trouble with part of this bash script in Linux where I respawn a new instance of script and kill the old one to prevent forking (Yes, I know 'exec' will not fork but this needs to be interactive) When the old instance is kill it pops up "Terminated!" in the middle of the new instance... (7 Replies)
Discussion started by: Azrael
7 Replies

6. Shell Programming and Scripting

Suppress "Where are you?" Message

biff n pdir=`pwd` # check for null parameter if ; then echo current directory $pdir ls -latr echo else p1=$1 #check for directory entry only if ; then pdir=$p1 echo current directory $pdir cd $pdir ls -latr echo #check for directory entry and file... (2 Replies)
Discussion started by: wtolentino
2 Replies

7. Shell Programming and Scripting

Error message while executing the shell script

Hi All, When I am trying to execute the below shell script I got this error message. script ========== #!/bin/bash /usr/java/jdk1.5.0_10/bin/java - classpath /var/lib/asterisk/agi-bin/mysql-connector-java-3.0.15-ga-bin.jar/: /var/lib/asterisk/agi-bin/jarfiles:... (4 Replies)
Discussion started by: ajayyaduwanshi
4 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

9. Shell Programming and Scripting

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 (5 Replies)
Discussion started by: helper2007
5 Replies

10. Shell Programming and Scripting

suppress bash's "Done" message

Hi, I'm running a background job in my bash script. But when the job quit, bash echos a message like "+ Done xterm". This is annoying. How can I suppress it? (5 Replies)
Discussion started by: momiji
5 Replies
Login or Register to Ask a Question