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
Error message while executing the shell script ajayyaduwanshi Shell Programming and Scripting 4 10-25-2007 04:12 AM
Suppress error message in unzip skwyer Shell Programming and Scripting 5 09-26-2007 02:20 PM
How to suppress error messages in script helper2007 Shell Programming and Scripting 5 01-17-2007 01:46 AM
suppress bash's "Done" message momiji Shell Programming and Scripting 5 08-31-2006 07:45 PM
problem with script and syntax error message ReV Shell Programming and Scripting 5 01-20-2006 03:50 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-31-2007
Registered User
 

Join Date: Nov 2005
Posts: 20
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
Reply With Quote
Forum Sponsor
  #2  
Old 12-31-2007
Klashxx's Avatar
HP-UX/Linux/Oracle
 

Join Date: Feb 2006
Location: Almerķa, Spain
Posts: 383
Use this:

Code:
FileCnt=`ls -lrt $DIR/* 2>/dev/null| wc -l`
Reply With Quote
  #3  
Old 12-31-2007
Moderator
 

Join Date: Dec 2003
Location: /dev/fl
Posts: 1,061
Code:
ls -lrt $DIR/* 2> /dev/null | wc -l`
Reply With Quote
  #4  
Old 12-31-2007
Registered User
 

Join Date: Nov 2005
Posts: 20
Thanks a lot
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 07:04 AM.


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