Spaces in files
Posted: Tue Oct 02, 2007 5:46 am
I want to iterate over the results of a find. So I've been doing this:
Only the problem is if I run this in a directory with contents like this
I'll get output like this:
you can see that "foo bar" is being separated into "foo" and "bar". Any ideas how I can prevent this?
The normal output of find will be able to distinguish by using a newline, can i parse that into an array somehow?
Code: Select all
index=0
for file in `find`
do
echo $index $file
index=`expr $index + 1`
done
Code: Select all
-rw-r--r-- 1 root root 2 2007-10-02 11:56 bar
-rw-r--r-- 1 root root 2 2007-10-02 11:56 foo
-rw-r--r-- 1 root root 2 2007-10-02 11:57 foo barCode: Select all
0 .
1 ./foo
2 ./bar
3 ./foo
4 barThe normal output of find will be able to distinguish by using a newline, can i parse that into an array somehow?
Code: Select all
.
./foo
./bar
./foo bar