[Cialug] [OT]: Shell script globbing

Eric Junker eric at eric.nu
Thu Dec 20 20:03:45 CST 2007


You can also test the exit code from ls to determine if the files exist. 
The code below seems to work.

#!/bin/sh

if ls *.bad > /dev/null 2>&1 ; then
   echo bad;
fi


Kendall Bailey wrote:
> You might want to discard the error message when no bad files exist
> 
> if [ `ls *.bad 2> /dev/null | wc -l` -gt 0 ]
> 


More information about the Cialug mailing list