2

I want to use f and v for variable. f *.mkv and v *.mp3

for f in *.mkv v in *.mp3; do 
   ffmpeg -i "$f" -i "$v" -vcodec copy merge_"$f"
done

I dont know how to do it properly. I am still new with bash shell scripting.

I hope someone can help me.

2
  • 1
    Do the mkv and mp3 files have common names? Are you trying to pair up files? Commented Jul 9, 2015 at 19:49
  • 1
    Did you look at: stackoverflow.com/questions/11215088/… might be similar or duplicate. Commented Jul 9, 2015 at 19:53

2 Answers 2

5

If the *.mp3 and *.mkv basenames are the same:

for f in *.mkv; do
    mp3name="${f%.mkv}.mp3"
    ffmpeg -i "$f" -i "$mp3name" -vcodec copy "merge_${f}"
done
Sign up to request clarification or add additional context in comments.

Comments

1

If you are looking for a way to loop through the variables the way it is expected to loop through with your original code, you can do this:

f=(*.mkv)
v=(*.mp3)
for((i=0;i<${#f[@]};i++));do
echo "${f[$i]} ${v[$i]}"
done

General assumption is, you have the same number of files for both mkv and mp3.

Or if the files have identical basenames, you can do this:

for f in *.mkv;do
v="${f/%mkv/mp3}"
echo "$f $v"
done

In "${f/%mkv/mp3}" mkv is being replaced by mp3 at the end.

See Bash Parameter Expansion for more info.

Comments

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.