find command in while loop - how to get control when no files found?

I have the following statement in script:

find ${LANDING_FILE_DIR}${BTIME_FILENAME_PATTERN2} -print | while read file; do
...
done

When there are no files located by the find comand it returns:

"find: bad status-- /home/rnitcher/test/....." to the command line

How do I get control in the script once the find behaves in this fashion? "$?" immediately following the done returns 0.

tia

A possible way:

findok=
find ${LANDING_FILE_DIR}${BTIME_FILENAME_PATTERN2} -print | \
while read file
do
   findok=Y
   ...
done

if [ -z "$findok" ]
then
   echo "No file found !"
done

Jean-Pierre.

Hi.

One could also break the pipeline into pieces, using scratch files to communicate, so that one could test the exit status of each part.

A more complex solution involves using another process for each piece, as explained in ``Answers to Unix'' Column: No. 003 -- quite inventive I think.

Some shells may offer pipefail -- bash and ksh, for example:

... cheers, drl

thanks for the posts :slight_smile: