Do you really want to change the song title to include both the artist and title information? Why?
Well, for one thing this will not work:
Code:
id3tag -2 --song='$artist" - "$title' "$i"
Single quotes make
everything inside them literal. So you're setting the title of the song to the literal string |$artist" - "$title|. You need to use double quotes only around variables, which still allow the values to be substituted.
(Unlike single quotes, double quotes allow $, ` and \ to be interpreted, which allows for variable and command substitutions and escape sequences.).
Actually, looking again, you're not even using variables, but functions. Functions aren't called by "$name", just "name" alone. So what you really need to be using is $(command) substitution:
Code:
id3tag -2 --song="$(artist) - $(title)" "$i"
Next, you're doing a lot of unecessary work to process the fields in your functions. Sed can do it all by itself. Try this:
Code:
id3info "$i"|sed -rn '\|TALB| s|.*:[ ](.*)$|\1|p'
You can learn more about sed
here.
Finally, I've been working on something similar (but more complex) myself for the last week, and I've found that working with music metadata is a real pain, particularly when trying to work with multiple formats. I don't see id3info/id3tag available on Debian, but for mp3 files I've had better success with mid3v2, the python-based tag reader. It has a much easier input and output format for using in shell scripts. You might give it a try.
Edit: One more thing I just noticed. You're simultaneously reading information from and writing to the same file. I'm not sure that's safe. It would be better for you to read the tag information into variables first and then write out the new values only after you have everything extracted.