[ale] Q: Bash: test for existence of any file matching a glib pattern.

Joe Knapka jknapka at kneuro.net
Sun Aug 8 16:08:50 EDT 2004


Hi folks,

A simple Bash question that google, the Bash FAQ, and the
comp.unix.shell FAQ have failed to answer. (Possibly man bash would
answer it, but I find I usually fall asleep before finding the
particular tidbit I'm looking for in that horrendously gigantic
manpage. Plus I expect there are folks on this list who do this
kind of thing six times before breakfast.)

I need to do this:

if (any file matching *.h exists); then do something; fi

The "any file matching *.h" test is defeating me. No variety of "[ -e
... ]" seems to work (quoting the "*.h" different ways, and so
forth). I've also tried

for f in *.h ; do something to $f ; done

That works except when there are *not* any *.h files, in which case it
binds f to the literal string "*.h" instead, which causes bad stuff to
happen in the "do something to $f" part. Since I'm doing this inside
of a generic rule in a common make file for a development tree, I
really need the command to work properly even in directories that
don't contain any *.h files (in which case it should simply do
nothing, not cause an error condition).

Any assistance is appreciated.

Thanks,

-- Joe

-- 
"We sat and watched as this whole       <-- (Died Pretty -- "Springenfall")
 blue sky turned to black..."
... Re-defeat Bush in '04.
--
pub  1024D/BA496D2B 2004-05-14 Joseph A Knapka
     Key fingerprint = 3BA2 FE72 3CBA D4C2 21E4  C9B4 3230 94D7 BA49 6D2B
If you really want to get my attention, send mail to
jknapka .at. kneuro .dot. net.



More information about the Ale mailing list