Help shell script to loop through files update ctl file to be sql loaded

I am currently trying to find a way to loop through files in a given directory and for each file modify a ctl file and sql load it. I have been using the sed command to change the infile, badfile parameters of the control file. I have not yet tried to sql load it.
Requirement: files are ftp to directory. Shell loops through the files and then using a master control file change the infile, badfile parameters with the file name. SQL load file.

I currently have been trying the following.
<<filename>> is what I am using to change in the ctl file.

export MY_DIR=/volume/files

for a in $MY_DIR/*ctl
do
sed -e "s/<<filename>>/$a/g" $a $a.ctl
done

I am wondering if their is a way to reference the infile, badfile directly in the ctl file instead. I also have an insert into a table where the filename that I am loading needs to be inserted. My method leaves me with a badfile with "name.ctl.bad" instead of just "name.bad". I am new to shell scripting so please be nice.

Thanks in advance.

I'm not sure whether this is what you are looking for:

badfile=${a%.ctl}.bad

[quote]