[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]



> Joe, are you looking for .h files in the current directory or system
> wide?   If you're just looking for the current directory, try this:
> 
> for f in `\ls *.h`; do echo "doing something to $f; done

This has the same trouble as "for f in *.h" -- it works great
when there *are* files matching the pattern, but it does the
wrong thing when there aren't any.

The answer turns out to be, "set the nullglob shell option,
eg shopt -s nullglob". That changes the behavior of glob
expansion: when nullglob is set, "*.h" always expands to
precisely a list of existing .h files in the current directory
(that is, if there aren't any files matching the pattern,
it expands to "" rather than "*.h").

Doubtless this will come back to bite me in some soft-tissue
area in the future, but for now, it works.

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


</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<ul><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><a name="00221" href="msg00221.html">[ale] Q: Bash: test for existence of any file matching a glob	pattern.</a></strong>
<ul><li><em>From:</em> fletch at phydeaux.org (Fletch)</li></ul></li>
</ul></li></ul>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="00215" href="msg00215.html">[ale] Q: Bash: test for existence of any file matching a glib	pattern.</a></strong>
<ul><li><em>From:</em> jknapka at kneuro.net (Joe Knapka)</li></ul></li>
<li><strong><a name="00217" href="msg00217.html">[ale] Q: Bash: test for existence of any file matching a glib	pattern.</a></strong>
<ul><li><em>From:</em> christopher at bergeron.com (Christopher Bergeron)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg00219.html">[ale] Q: setting up NetScrape 7.1, j2re-1.4.2_05, and RH-7.3</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg00221.html">[ale] Q: Bash: test for existence of any file matching a glob	pattern.</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg00217.html">[ale] Q: Bash: test for existence of any file matching a glib	pattern.</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg00221.html">[ale] Q: Bash: test for existence of any file matching a glob	pattern.</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#00220"><strong>Date</strong></a></li>
<li><a href="threads.html#00220"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>