export ok=0 # means files are there and non-empty
test_sz() { # function to return 0 or 1
{
sz="$1"
sz=$( wc -c "$sz)
sz=${sz:0:1} # first character of sz string
retval=0 # assume failure
[ $sz -gt 0 ] && retval=1
return retval
}
[[ -e 1.txt && -e 2.txt && 3.txt ]] && ok=1 || echo 'files missing'
if [ ok -eq 1 ]; then
[[ $(test_sz 1.txt) -eq 0 || $(test_sz 2.txt) -eq 0 || $(test_sz 3.txt) -eq 0 ]] && ok=0
fi
if [ ok -eq 0 ] ; then
echo 'file(s) did not pass requirements'
exit 1
fi
# rest of script here
This can be shortened, but it is meant to be a clear example.
Please, try the following as you are in /opt/thomas/
for f in 1.txt 2.txt 3.txt; do
if ! [ -s "$f" ]; then
echo "$f does not exist or is empty"
echo "Exiting..."
exit 1
fi
done
# Continue with script, here.