Jump to content

How do I change a filename extension in a script?

Recommended Posts

Hi, I made a simple audio-to-wav conversion workflow using ffmpeg (the entire command is 

ffmpeg -i {query} {query}.wav && exit

How can I make it so it doesn't just append the .wav extension but actually changes it (so, from file.mp3 to file.wav and not file.mp3.wav)?



Link to comment

Start by using with input as argv over with input as {query}. Then, quote your arguments or you’ll have a bad time spaces and the like. Finally:


ffmpeg -i "${1}" "${1%.*}.wav"


Note the && exit isn’t doing anything unless you have lines below that in your script.


The explanation for the code above comes down to parameter substitution. When you have ${some_variable}, ${some_variable%.*} means “delete from some_variable any text from (and including) the last . to the end of the string”.


Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...