[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How to escape "find" result



Once upon a time Try KDE said...
> Hi,
> 
> I'm trying to run the following script:
>   for f in $(find . -name "*.txt"); do cmd1;cmd2;cmd3; done
> ,where cmd1, cmd2 and cmd3 are arbiturary commands. The problem is, if 
> the found file names contain a space , for example "part1 part2.txt" 
> will be interpreted as "part1" and "part2.txt". I'm thinkin an esacping 
> tool may be able turn it into "part1\ part2.txt" before passing it to 
> "for" loop. Any thought?

$ find . -name "*.txt" | while read f ; do
> cmd1 "$f"
> cmd2 "$f"
> cmd3 "$f"
> done

I've found that is the easiest way to use find when you have spaces in
filenames. Dont forget the quotes arounf $f when you use it, or you get
the same problem when running the commands (ie appears as two args
instead of one).



Reply to: