The reason why this is not working is because everything between ` `
is executed before the xargs
execution. But if you quote it in ' '
, then it is going to be passed correctly, but xargs
is not going to parse or expand it.
But you can pipe to the bash function!
convertFile() {
while read -r filename; do
newFilename="${filename:0:-3}mkv"
ffmpeg "$filename" -vcodec libx264 "$newFilename"
done
}
find . -name "*.avi" | convertFile
Please note that instead of sed
I am using bash string manipulations. The reason for that is that your file can sometimes contain avi word inside, like gravity. That is why more fail-proof way was used.