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

Handle paths with spaces



This is my directory structure:
.
|   a.sh
|   a.txt
|
+---foo bar
|       b.txt
|
+---santa
|   |   c.txt
|   |
|   \---humpty dumpty
|           e.txt
|
\---test
        d.txt

I want to do some operation on each file ending with .txt. However,
this script wouldn't work because in each iteration it gets one word
from the output of find.

Script:

for file in `find -name "*.txt"`
do
    echo file: $file
done

Execution:

$ sh a.sh
file: ./a.txt
file: ./foo
file: bar/b.txt
file: ./santa/c.txt
file: ./santa/humpty
file: dumpty/e.txt
file: ./test/d.txt

You can see how ./santa/humpty dumpty/e.txt has been broken into two
iterations. Any way to resolve this?


Reply to: