|
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.
|