Linux – How to do a for loop of filenames with spaces using find

bashfindlinux

I have the following script – its supposed to loop files names using find but it seams to break the files names up by a space? I need the file names to remain intact

#!/bin/bash

for file in `find -name "*.avi"`
do
./myscript $file
done

Can anyone help me?

Thanks

Best Answer

find -name "*.avi" -print0 | xargs -0 -n 1 echo

You don't have to echo in xargs:

find -name "*.avi" -print0 | xargs -0 -n 1 ./myscript