I've seen several posts on very similar queries, but here is my use case:
A shell script (ksh in my case) which has a step to check a dir for files ending in .txt or .TXT and assign a variable, INPUT_FILE, if present, for processing further in the script. If these file types are not present, exit out of whole job (exit 0).
This was working for when a) files were present, b) ignoring directories, c) ignoring zero byte files, but when the dir was empty, it was still setting the INPUT_FILE to a null value and failing. What am I missing?
code
change to some /dir
if [ -s `ls -pt | grep -v / | grep -i .txt` ];
then
INPUT_FILE=`ls -pt | grep -v / | head -1`
echo "${INPUT_FILE} exists. Moving on to import"
else
echo "No file to import. Exiting job."
exit 0
fi
error snippet showing echo with "null" value
exists. Moving on to import
Thanks