Suggestion from the bash nerd (heh
): use "-r" (or -f, but -r is better) instead of "-n" when checking the filename. -n simply checks for a non-zero length string, -f checks that a file exists (which would include a 0-length check), but -r checks if the file exists and is readable (permissions, etc.).
Since you're nautilizing it, I'd also check that the output directory is writeable -- it might go something like...
Code:
MYDIR=`dirname "${filename}"`
if [ ! -d "${MYDIR}" ] || [ ! -w "${MYDIR}" ]; then
echo "Output directory missing or unwritable, exiting."
exit 1
fi