On Thu, May 05, 2011 at 09:17:01PM -0700, website reader wrote:
> What is the correct syntax for the following simple bash script test command
> on (1) when using the wild card character * to match?
> 
> I have a set of files, and simply want the test to locate at least one file,
> but the wild card * asterisk character seems to mess up the test command by
> finding too many matches.
> 
> (1)   if test -e m* ; then echo "found" ; fi
> 
> If I write
> 
> (2) if test -e `ls m* | head -1` ; then echo "found"; fi
> 
> and don't have any files matching m*, the bash script executes, finds
> nothing (as expected) but gets a success on the 'ls m* | head -1` script
> execution and then echos "found"
> 
> How is the bash script written correctly so it will echo found if any m*
> files exist?

The ls stands in for the -e test:
 
FILE_THERE=`ls m* 2>/dev/null | head -1`
if [  $FILE_THERE ];
then
    echo found $FILE_THERE 
fi


-- 
      Michael Rasmussen, Portland Oregon  
  Trading kilograms for kilometers since 2003
    Be appropriate && Follow your curiosity
          http://www.jamhome.us/
The Fortune Cookie Fortune today is:
Chickens are pets with benefits.
    ~ Michael Rasmussen
_______________________________________________
PLUG mailing list
[email protected]
http://lists.pdxlinux.org/mailman/listinfo/plug

Reply via email to