Thanks for replying and including the solution you ended up using.
Btw, that looks like C shell code due to the redirection syntax. You
really don't want to use the C shell for any kind of production work; it's too buggy and idiosyncratic. Google for "101 reasons not to use the C shell".
A problem with both my code and yours is the assumption that the current directory is readable and thus ls(1) won't fail due to anything other than a wildcard not being replaced by the shell. In the real world this is a reasonable assumption, but truly defensive shell scripting would check for that with and additional if statement of
[ -r . ]
Because both of our routines use ls(1) they pay a performance penalty for the fork() and exec() required to run ls(1). If all built-in commands could be used it would be much faster.
For example, using
for i in *.[Ll][Aa][Ss]; do break; done would result in the wildcard being expanded but the loop breaking the very first time through. The value of
i will either be a real filename (as the wildcard was expanded) or the string
*.[Ll][Aa][Ss] and a simple
[ -e "$i" ] will determine that. This solution requires no fork/exec and will be much faster.
But I'm betting that the performance is not a big issue anyway.