Help on shell script (string operations)

Hey everyone. So the background of the problem is that the ps3 does not support the mkv container, but DOES support the avi one. Here is the script to convert one file with the name hardcoded in:

#!/bin/sh                                                                   
mencoder -oac mp3lame -lameopts cbr=128 -ovc xvid -xvidencopts bitrate=1200  VIDEO_NAME.mkv -o VIDEO_NAME.avi
rm subtitles.srt #Command creates a subtitles.srt file that I don't want

I would like to modify this script so that I can specify an input as a directory, and it will convert all mkv files to avi files with only the extensions changed (same file name).

I have limited experience in shell scripting, but I'd imagine I would have to do something like

for i in ls *.mkv

then do the original converting command with the string VIDEO_NAME.mkv and the modified string VIDEO_NAME.avi

Any help is greatly appreciated!

Maybe this.

#!/bin/sh
cd "$1"  ||  { echo "Arg 1 must be a directory" 2>/dev/stderr; exit 1; }
OPTIONS="-oac mp3lame -lameopts cbr=128 -ovc xvid -xvidencopts bitrate=1200"
for f in *.mkv; do
    AVI="${f%.*}.avi"
    mencoder $OPTIONS "$f" -o $AVI
done

${f%.*} prints the contents of $f with everything stripped off from the last period to the end.

Thanks!