ID3 tagging script

I'm trying to get a little script working with DropScript 0.5 that edits the ID3 tags of an MP3. Here's what I've got:

#!/bin/sh

# Strip directory part but leave extension.
in_base=`basename "$@"`
# Strip extension.
in_noext=`echo "$in_base" | sed 's/\.[^.]*$//'`

/opt/local/bin/id3v2 --TPE2 "$in_noext" "$@"

It works fine when I drop one file on it at a time, but when I drop more than one file on it, it's writing a list of all the files to each individual file. I know I need to replace the first

$@

with something that will only look at each file, not all the files. But I'm such a shell scripting newb, that I don't know what to replace it with. Any ideas?

Many thanks in advance for any help!

I got some help via the DropScript author via email:

Can anyone point me towards a for loop example?

Use a for loop.

In a POSIX shell, basename is not needed:

for file in "$@"
do
   in_base=${file##*/}
   in_noext=${in_base%.*}
done

Thank you cfajohnson. The for loop seems to be working, but now I think I need a for loop for the id3v2 command because it's tagging each file with the first file's name. Or do I need to put the id3v2 command into the first loop somehow? Here's what I've got right now:

#!/bin/sh

# Strip directory and extension.
for file in "$@"
do
   in_base=${file##*/}
   in_noext=${in_base%.*}
done

# Tag each file's ID3 field "Album Artist" (a.k.a.-"Band/Orchestra/Accompaniment") with the file name
/opt/local/bin/id3v2 --TPE2 "$in_noext" "$@"

I figured it out. Here's my working script. Again, thanks for the help!

#!/bin/sh

for file in "$@"
do
   # Strip directory and extension of each file.
   in_base=${file##*/}
   in_noext=${in_base%.*}

   # Tag each file's ID3 field "Album Artist" (a.k.a.-"Band/Orchestra/Accompaniment") with the file name
   /opt/local/bin/id3v2 --TPE2 "$in_noext" "${file}"
done