1

I have a file named "01 - Welcome To The Jungle.mp3", and I want to do eyeD3 -t "Welcome To the Jungle" 01 - Welcome To The Jungle.mp3 to modify the tag of the all the files in the folder. I've extracted from the file with awk: "Welcome To The Jungle" doing:

#!/bin/bash
for i in *.mp3
do
eyeD3 -t $(echo ${i} | awk -F' - ' '{print $2}' | awk -F'.' '{print $1}') ${i}
done

It doesn't work. Neither the whole "$(echo S{i}....)" nor the "${i}" seem to work for replacing the names of the respective files.

2 Answers 2

1

You need to prevent word splitting on IFS (default: space, tab, newline) by shell, as your input filename contains space(s). The typical workaround is to use double quotes around the variable expansion.

Do:

for i in *.mp3; do eyeD3 -t "$(echo "$i")" | ...; done

You can leverage here string, <<<, to avoid the echo-ing:

for i in *.mp3; do eyeD3 -t <<<"$i" | ...; done
Sign up to request clarification or add additional context in comments.

Comments

0

You need to double-quote variables that may contain spaces, as @heemayl already pointed out.

Also, in this example, instead of using awk, it would be better to use native Bash pattern substitution to extract the title, for example:

for file in *.mp3; do
    title=${file%.mp3}
    title=${title#?????}
    eyeD3 -t "$title" "$file"
done

That is:

  • Remove .mp3 at the end
  • Remove the first 5 characters (the count prefix NN -)

2 Comments

Thank you so much @janos! I didn't even know you could do that! And it looks so much more intuitive than the awk command!
No, Thank you. I think I understand it now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.