This is the shell script I wrote to rip audio cd's to MP3. Maybe you can adapt it or use parts to help you.
Code:
if [ $# -ne 1 ]
then
echo "Usage: " `basename $0` "<output directory>"
exit
fi
if [ ! -d $1 ]
then
echo "$1 is not a valid directory"
exit
fi
# Need determine the number of tracks on the disc
n_files=`cdparanoia -Q 2>&1 | egrep "^ *[0-9]+\." | wc -l`
if [ $n_files -lt 1 ]
then
echo "ERROR - Can't find any tracks - is the CD inserted?"
exit
fi
echo -e "Ripping $n_files files..."
for i in `seq 1 $n_files`
do
cdparanoia -q $i - | lame --silent -h --vbr-new -V 4 - `printf "%s/track_%02d.mp3" $1 $i`
echo - Sucessfully ripped track $i
done
echo "Ripping complete"