[Nottingham] Bash: test "file exists" - gotme again
david wolfson
eaxdrw at nottingham.ac.uk
Thu Oct 14 14:23:23 BST 2004
I'm back in bash land, with another gotme, this time of my own making.
It's a similar setup, where I want to batch process a lot of files. I
thought I'd set up a while loop, to keep running as long as a file of
the given file name exists, but it always goes 'a file too far' (i.e. if
my last file is file_119.tif and it tries to run file_120.tif).
There's some other gumph in the loop (sorting out zero padding and the
like), but the basic structure is as follows
while [[ -a "$filename" ]]; do
filename=$basefilename$file_no.tif
echo "processing file: "$filename
file_no=$(($file_no + 1))
done
I've tried several other forms such as;
until [ ! -z $filename ]; do
but with the same outcome; always one file too many. At the moment this
is an annoyance, but it'll soon become a real pain.
If anyone can spot my blooper, or point me in the direction of some
advice (I got this far from the evaluation section of the man pages) I'd
be grateful.
Cheers,
Dave
This message has been scanned but we cannot guarantee that it and any
attachments are free from viruses or other damaging content: you are
advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.
More information about the Nottingham
mailing list