Wait for Background Process to complete

I am attempting within a for-loop, to have my shell script (Solaris v8 ksh) wait until a copy file command to complete before continueing. The specific code is:

for files in $(<inputfile.lst)
do
mv directory/$files directory/$files
ksh -m -i bg %%
wait $!
done

I am shaky on the procedure to set something in background. Is there a way to set something in background then use a like a grep on ps -ef, passing its id to the wait command? Or am I just really out there? Thanks in advance for any replies.

...Gozer13

command&
wait $!

Simple example to test this stuff


$ ./wait.sh 
Thu Feb 10 15:59:50 CST 2005
Thu Feb 10 16:00:00 CST 2005
hello
$ cat wait.sh
date
sleep 10 &
wait $!
date
echo "hello"
$ 

Thanks guys, I have tried solutions like this, however maybe I entered something incorrect. I will try again.