If you just want to skip any file ending with PITCHED.mp3
I would use a case statement
case "$mp3" in
*PITCHED.mp3)
echo skipping "$mp3"
;;
*)
#repitch as before
;;
esac
Question
I want to change pitch, using sox, of every mp3 in every music folder I have. I wrote this in bash:
function pitch_mp3 {
for mp3 in /home/mp3s/*/*.mp3
do
cd "$(dirname "$mp3")"
output=$(basename "$mp3" .mp3)PITCHED.mp3
sox -S "$mp3" -C 192 "$output" pitch 50
done
}
It adds the pitch to for example 01song.mp3 and the output file is 01songPITCHED.mp3. But what happens is that sox do the job first time, but then goes again cycling through the folders and add pitch to already pitched mp3-s, so they file name turned out to be 01songPITCHEDPITCHED.mp3. I stopped it when I noticed, so I don't know if it is going to add pitch for the third time etc..
Why and how to fix this?
Solution
If you just want to skip any file ending with PITCHED.mp3
I would use a case statement
case "$mp3" in
*PITCHED.mp3)
echo skipping "$mp3"
;;
*)
#repitch as before
;;
esac
OTHER TIPS
function pitch_mp3 {
for mp3 in /home/mp3s/*/*.mp3
do
[[ "$mp3" = *PITCHED.mp3 ]] && continue
cd "$(dirname "$mp3")"
output=$(basename "$mp3" .mp3)PITCHED.mp3
sox -S "$mp3" -C 192 "$output" pitch 50
done
}
I'd also make the extension a variable so I didn't have to retype it, but that's just me.