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 08-26-2008
msb65 msb65 is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 89
For Loop Question

Hi, I am writing a bash shell script. I will have a section of code devoted to a for loop:

for FILE in *.hdf *.L2; do
echo hello world
done

The complication is that sometimes there will not be any files with a ".hdf" extension, or sometimes there won't be any with a ".L2" extension. Since there are files with other extensions I can't just say "for FILE in *; do". How can I make my script loop through a number of times equal to the amount of files ending in .hdf or .L2, but not care if sometimes either of those filetypes doesn't exist?

Mike