I would do this:<br><br>if [ `ls *.bad | wc -l` -gt 0 ]<br>&nbsp;&nbsp; then<br>&nbsp;&nbsp; echo Bad<br>&nbsp;&nbsp; fi<br><br>Chris<br><br><div class="gmail_quote">On Dec 20, 2007 12:58 PM, Brown, David [DNR] &lt;<a href="mailto:David.Brown@dnr.iowa.gov">
David.Brown@dnr.iowa.gov</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Another way to check if any &quot;.bad&quot; files exist is piping the ls output
<br>to grep, searching for &quot;.bad&quot;, with the count flag set and storing this<br>output in a variable.<br><br>E.g.<br> &nbsp; &nbsp; &nbsp;N_bad_files=`ls | fgrep -c &quot;.bad&quot;`<br><br> &nbsp; &nbsp; &nbsp;if [ $N_bad_files -gt 0 ] ;then
<br> &nbsp; &nbsp; &nbsp; &nbsp;echo bad<br> &nbsp; &nbsp; &nbsp;fi<br><div><div></div><div class="Wj3C7c"><br><br><br>-----Original Message-----<br>From: <a href="mailto:cialug-bounces@cialug.org">cialug-bounces@cialug.org</a> [mailto:<a href="mailto:cialug-bounces@cialug.org">
cialug-bounces@cialug.org</a>] On<br>Behalf Of Daniel A. Ramaley<br>Sent: Thursday, December 20, 2007 11:22 AM<br>To: Central Iowa Linux Users Group<br>Subject: [Cialug] [OT]: Shell script globbing<br><br>I have what should be a simple shell scripting problem. If any .bad
<br>files exist, then the script should do some stuff (display an error, do<br>some cleanup, and exit, though for testing i&#39;ve simplified it). So far<br>i&#39;ve come up with 2 solutions, one requiring a variable and running
<br>&quot;ls&quot;, the other requiring a seemingly superfluous &quot;for&quot; loop. Is there a<br><br>more elegant solution i&#39;ve not discovered?<br><br>My first attempt, doesn&#39;t work because -e expects only 1 argument and
<br>there may be multiple .bad files:<br> &nbsp; &nbsp;if [ -e *.bad ] ; then<br> &nbsp; &nbsp; &nbsp; &nbsp;echo Bad<br> &nbsp; &nbsp;fi<br><br>My first working solution, letting ls handle the glob and doing a string<br><br>comparison on the result:<br> &nbsp; &nbsp;GLOB=`ls *.bad 2&gt; /dev/null`
<br> &nbsp; &nbsp;if [ -n &quot;$GLOB&quot; ] ; then<br> &nbsp; &nbsp; &nbsp; &nbsp;echo Bad<br> &nbsp; &nbsp;fi<br><br>My second solution; the &quot;if&quot; is required because if no .bad files exist<br>the loop will still run once with file set to the literal &quot;*.bad&quot;:
<br> &nbsp; &nbsp;for file in *.bad ; do<br> &nbsp; &nbsp; &nbsp; &nbsp;if [ -e $file ] ; then<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo Bad<br> &nbsp; &nbsp; &nbsp; &nbsp;fi<br> &nbsp; &nbsp;done<br><br>------------------------------------------------------------------------<br>Dan Ramaley &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Dial Center 118, Drake University
<br>Network Programmer/Analyst &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 2407 Carpenter Ave<br>+1 515 271-4540 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Des Moines IA 50311 USA<br>_______________________________________________<br>Cialug mailing list<br><a href="mailto:Cialug@cialug.org">
Cialug@cialug.org</a><br><a href="http://cialug.org/mailman/listinfo/cialug" target="_blank">http://cialug.org/mailman/listinfo/cialug</a><br>_______________________________________________<br>Cialug mailing list<br><a href="mailto:Cialug@cialug.org">
Cialug@cialug.org</a><br><a href="http://cialug.org/mailman/listinfo/cialug" target="_blank">http://cialug.org/mailman/listinfo/cialug</a><br></div></div></blockquote></div><br>