The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #4 (permalink)  
Old 03-04-2003
TioTony's Avatar
TioTony TioTony is offline
Bit Pusher
 

Join Date: Oct 2001
Location: Southern California
Posts: 332
The '-e' in the 'if' statement checks the current directory to see if the file exists. You do not need to build a data structure containing the 'ls' input. You can simply check the directory directly. In the example, what will happen is it will do the following:

if janfile.tar exists, then print found and exit
if janfile.jar exists, then print found and exit
if jan.rpt.Z exists, then print found and exit

There is no reason to compare 'mylist' against every file in the directory. Suppose you have 1000 file in the directory and you only care if janfile.tar exists. Why would you want to compare it to the other 999 files when you can basically have the program asks if it exists or not without having to iterate through each filename? The for loop is looping through the values of mylist and "asking" if those files exist, it does not care about the other file that may or may not be in that directory. Hope that explains it.