Re: Elegant bash solution for testing existence of any files?



Janis Papanagnou wrote:
chriswaltham@xxxxxxxxx wrote:
I'm trying to write a reasonably basic script to convert varied image
file formats to EPS-formatted files. The script runs every 15 seconds,
and checks for the existence of *.{gif,jpg,tiff} files at that interval
to decide whether or not it has something to process. The files are
"fed" into the directory the script resides in automatically.

At the moment, I'm using the "if [ -a * ]" syntax to start a processing
loop, but that is incorrect if >1 files exist.

You are using * so I assume that only files of the given types are
present in that directory. You may set - * and then test whether
$1 is an accessible file. (But why not simply loop over the files
of given type?)

Janis

I was using * as the extension of the files doesn't matter; only that
file(s) exist. Once it's ascertained that files exist, the conversion
process begins -- amongst other things it changes filename case to
ensure sanity, and then (depending on the file extension) does the
processing.

This is one of those times where I can think of a ton of ways to solve
the problem, but can't help but think there's an easier/better/more
elegant way than this:

ls_output=`ls *.tif*`
if [ -z $ls_output ]
then
echo "no files exist to convert, skipping..."
else
echo "files exist, loading conversion process"
convertProc # run conversion (incl. sanity & format checking)
fi


Chris

.



Relevant Pages

  • Re: Elegant bash solution for testing existence of any files?
    ... file formats to EPS-formatted files. ... "fed" into the directory the script resides in automatically. ... Once it's ascertained that files exist, the conversion ... echo "files exist, loading conversion process" ...
    (comp.unix.shell)
  • Re: Elegant bash solution for testing existence of any files?
    ... file formats to EPS-formatted files. ... "fed" into the directory the script resides in automatically. ... Once it's ascertained that files exist, the conversion ... echo "files exist, loading conversion process" ...
    (comp.unix.shell)
  • Re: echo oddities...
    ... > The whole beginning of the string fails to print. ... > using PRINT instead of ECHO and get the same output. ... > this code from a much larger script and tested it on its own and I ... conversion to int because "+" is not a string operator... ...
    (php.general)
  • RE: blocking file formats in the interior of the network
    ... The script: (asterisks denote a new line and should be deleted. ... We are seeking a solution which can detect/block different file formats ... EARN A MASTER OF SCIENCE IN INFORMATION ASSURANCE - ONLINE ... The NSA has designated Norwich University a center of Academic ...
    (Security-Basics)
  • Re: Batch renaming in subfolder tree
    ... The only thing still missing is recursiveness. ... than bash script. ... Again, it's in PHP, and this ... // bit of feedback while doing the conversion ...
    (alt.os.linux.suse)