[Nottingham] Bash: test "file exists" - gotme again

Peter Chang Peter.Chang at nottingham.ac.uk
Thu Oct 14 14:38:29 BST 2004


David,

> 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

This is an error in program flow - you're testing the filename at the
wrong point. Seeing as bash doesn't have a do-while construct, you should
use a combination while-true and if-break.

Peter





More information about the Nottingham mailing list