File Name with spaces

I need to read pdf files copied in a unix directory.I tried using the for loop with find command but the file names is cutting off at the spaces.Below is the code I tried.

for FILENAME in `find $DIR_FILE/ -name "*.pdf" -mindepth 1 -maxdepth 1 -mmin +60 ` ##Needs to be changed later +60 to -60
do
  cat "$filename"
  logmsg "filename1 ${FILENAME}"
  AGTCODEFILE=`basename $FILENAME`
  echo $AGTCODEFILE
  logmsg "filename ${AGTCODEFILE}"
done

Can anybody please help me on this?

just use different flow control:

find $DIR_FILE/ -name "*.pdf" -mindepth 1 -maxdepth 1 -mmin +60 |
while read filename ; do

cat "$filename"
logmsg "filename1 ${FILENAME}"
AGTCODEFILE=`basename $FILENAME`
echo $AGTCODEFILE
logmsg "filename ${AGTCODEFILE}"

done

I tried it ,but didn't work.I am trying something like below

 
for FILENAME in `find $DIR_FILE/-name *.pdf | awk 'gsub(/ /,"_")' -mindepth 1 -maxdepth 1 -mmin +60` ##Needs to be changed later +60 to -60
#cat "$filename"
logmsg "filename1 ${FILENAME}"
AGTCODEFILE=`basename $FILENAME`
echo $AGTCODEFILE

done

But ,getting error.Can somebody pls help?

Bar a minor typo the post from quirkasauus cures the problem reported in post #1 (filenames with spaces).
Also the variable name $filename is case-sensitive. It is not the same as $FILENAME.

With minor correction:

find "${DIR_FILE}"/ -name "*.pdf" -mindepth 1 -maxdepth 1 -mmin +60 | while read FILENAME
do
    cat "${FILENAME}"
    logmsg "filename1 ${FILENAME}"
    AGTCODEFILE=`basename "${FILENAME}"`
    echo "${AGTCODEFILE}"
    logmsg "filename ${AGTCODEFILE}"
done

The construct of "for filename in list" is never ever useful for an open-ended list or where there may be filenames contining spaces. I have absolutely no idea where the construct came from because I have never seen it in a unix book and never seen it in a commercial environment.

Btw: If you are "getting error" please copy/paste the command and the matching error message.

A version that is safe for all legal filename characters (including newline ... as abhorrent as it may be in such a context ;)):

find "$DIR_FILE" -name \*.pdf -mindepth 1 -maxdepth 1 -mmin +60 -exec sh -c '
    for FILENAME; do
        cat "$FILENAME"
        logmsg "filename1 ${FILENAME}"
        AGTCODEFILE=`basename $FILENAME`
        echo $AGTCODEFILE
        logmsg "filename ${AGTCODEFILE}"
    done    
' sh {} +

Like methyl, I too assumed that $filename is a typo of $FILENAME. If it is not, if what you shared is a fragment of a script and $filename is a different variable, then it could trivially be passed into the shell script as the first positional parameter (in the sample code above, between "sh" and "{}").

Regards,
Alister