Programming Tips - bash: How can I change the extension (suffix) of a file in a bash script?

Date: 2009jul8 Language: bash OS: Linux Q. bash: How can I change the extension (suffix) of a file in a bash script? A. Use the ${} construct in bash. For example, to change the extension of variable $I from .flac to .mp3 and save in variable $MP3 do this:
MP3=${I/\.flac/.mp3}
Here is a script that converts a folder of .flac files to .mp3:
#!/bin/sh for I in *.flac; do MP3=${I/\.flac/.mp3} ffmpeg -i "$I" "$MP3" done