Order text display not correct.

My shell script below for import data to Oracle

it run okay. but the text display not correct follow order command executed.

=========================Shell Script code=================

#!/bin/sh

#directory = ${1-'pwd'}

#run import data with SQLLoader
runSQLLoader()
{
/home/oracle/app/oracle/product/11.1.0/db_2/bin/sqlldr test/12345@orcl control=$1 bad=$2 log=$3 discard=$4 data=$5 direct=TRUE;
if [$? -ne 0]
then
return 1
else
return 0
fi
}

ARGS=1
filecontrol="ControlFile/test.ctl"

if [ $# -ne "$ARGS" ];
then
directory=`pwd`
else
directory=$1
fi

for file in $(find $directory -type f )
do
fname=`basename $file`

#display the file to miport data
echo "Excute importing file : $fname "

#asking user waiting for this job finish
echo "Please waiting for you look finished task"

errorfile="Error/$fname"
processedfile="Processed/$fname"
badfile="Processed/bad$fname"
discardfile="Processed/discard$fname"
logfile="Processed/log$fname"

#run function above
runSQLLoader $filecontrol $badfile $logfile $discardfile $file;
#get result of importing data if 1 have error or 0 it importing okay
if [$? -ne 0]
then
echo "Error ! Have an error happen during import data "
mv "$file" "$errorfile"
else
echo "Finish importing file : $fname"
mv "$file" "$processedfile"
fi
done | sort

exit 0
======================End Shell Script code=================

Result display is not correct

Excute importing file : test01
Excute importing file : test02
Finish importing file : test01
Finish importing file : test02
Load completed - logical record count 6369.
Load completed - logical record count 7925.
Please waiting for you look finished task
Please waiting for you look finished task
SQLLoader: Release 11.1.0.6.0 - Production on Fri Nov 9 04:20:30 2007
SQL
Loader: Release 11.1.0.6.0 - Production on Fri Nov 9 04:20:31 2007

correct order must be like this

Excute importing file : test01
Please waiting for you look finished task
SQL*Loader: Release 11.1.0.6.0 - Production on Fri Nov 9 04:20:30 2007
Load completed - logical record count 6369.
Finish importing file : test01

Excute importing file : test02
Please waiting for you look finished task
SQL*Loader: Release 11.1.0.6.0 - Production on Fri Nov 9 04:20:31 2007
Load completed - logical record count 7925.
Finish importing file : test02

I did not why it display like that. :eek:

Please help me for correct order follow my run command in script ?
or please explain for me more about what happen when I print out the text. :frowning:

Thank so much for your help.

Silly me..

I had to read through you script to discover what's happenning here, whereas a simple inspection of the results you are getting reveals the situation.

Your output statements appear as alphabetically sorted, because you have piped the output of the "for" loop to a sort command.

-Rgds/ipzig

Thank you so much ipzig. I am a newer using the shell script and maybe I forgot it.

Thanks.