D&C GLug - Home Page

[ Date Index ] [ Thread Index ] [ <= Previous by date / thread ] [ Next by date / thread => ]

RE: [LUG] Bash question

 

Title: RE: [LUG] Bash question

 

> NO_OF_FILES=`ls ${DIRECTORY}/*.eps|wc -l`

Uses two child processes, more efficient to save the list of files into an array, then look at the length of the array:

files=($directory/*.eps)
no_of_files=${#files[*]}

You CAN use test if you want Bourne shell syntax, or you can:

if (( $no_of_files > 0 ))
then
   # do stuff
fi


Clive


________________________________________________________________________
This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________