View Full Version : Can someone help with a simple bash script?

June 7th, 2010, 08:35 PM
I have some .ogg music files that I need converted to .mp3. I've used the command
for file in *.ogg;do oggdec -o - "$file"|lame -h -V 4 –-vbr-new - "$(basename "$file" .ogg).mp3";done
before to convert every file in a folder, but I'd like to be able to just run the script and have it convert every .ogg in my Music folder. My Music folder is set up like Music>Artist>Album>Song.ogg. Can anyone help me out?

Thank you :)

June 7th, 2010, 08:42 PM
I don't remember the exact syntax, but google for ...

find dir -name *.ogg -exec ...

June 7th, 2010, 08:43 PM
You could try something like

find /path/to/music -name "*.ogg" | while read file

'file' would remain your variable. I think this should work.

June 7th, 2010, 08:43 PM
and many others

June 7th, 2010, 08:44 PM
Not sure I understand corretly, but are you saying that you have multiple directories separated for each artists or such and you want to covert all of them at one shot ?

Between pushd and popd, you are already in the OGG directory. Replace 'echo $x $y $z' with whatever command(s) you want to run.


foreach file (`find <top music dir> -name "*ogg" -print`)
set dir=$file:h
pushd $dir
echo "changing dir to $dir.."
set x = $file:t
set y = $file:r:t
set z = $y."mp3"
echo "$x $y $z"

June 8th, 2010, 03:34 AM
Thank you all, but I found the program ogg2mp3 which has worked wonderfully.

Thanks :)