The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 09-19-2007
lumdev lumdev is offline
Registered User
  
 

Join Date: Sep 2006
Location: Belgium
Posts: 6
For loop statement - catch error

I'm having a question about for loops. (bash)

I have the following for example:

for file in `ls *.txt`
do
read file ...
done

Now when there is a file present there is no problem, now when there is no file present I get the following output in my standard mail box : "No such file or directory" Script is executed via crontab.

Now I want to catch the above error so I don't get it in my mail any more, but I have no idea how to do this.

I can make an if statement first "if [ -f *.txt ] ...", but there must be a better solution.

Thx.