There are two files abc_123.dat
and abc_345.dat
if at least one file exists then enter into the loop and remove file and exit.
In first iteration, deleting files successfully
but "else" statement executing after deleting files."else" should execute only if there is no file in the directory. For loop only to check abc*.dat file exists or not.
INPUTDIR=/path/with/files
for i in $INPUTDIR/abc*.dat
do
if [ -f $i ]; then
echo "delete data from table..."
cd $INPUTDIR
ls -t abc*.dat | sort > ABC.lst
cat ABC.lst | while read line
do
rm $line
done
else
echo "File does not exist, exiting.."
exitcd=44
fi
done
return $exitcd