Here's a small complete shell test for what you want - execute it somewhere safe, e.g. while in /tmp:
# Prepare
rm -rf root
mkdir root
mkdir root/1
touch root/1/a
touch root/1/b
#touch root/1/"b with spaces"
mkdir root/2
touch root/2/c
mkdir root/2/3
touch root/2/3/d
# Find
echo --- Find
find root
# Test
echo --- Test
files=(`find root -type f`)
echo $files
# Print whole array
flen=${#files[*]}
for (( i=0; i < $flen; i++ )); do
echo files[$i] = ${files[i]}
done
The output of this is:
--- Find
root
root/1
root/1/a
root/1/b
root/2
root/2/c
root/2/3
root/2/3/d
--- Test
root/1/a
files[0] = root/1/a
files[1] = root/1/b
files[2] = root/2/c
files[3] = root/2/3/d
Beware, however, of spaces in file - if you uncomment the commented touch above by removing #
in front of this line:
#touch root/1/"b with spaces"
you will get the following:
--- Find
root
root/1
root/1/b with spaces
root/1/a
root/1/b
root/2
root/2/c
root/2/3
root/2/3/d
--- Test
root/1/b
files[0] = root/1/b
files[1] = with
files[2] = spaces
files[3] = root/1/a
files[4] = root/1/b
files[5] = root/2/c
files[6] = root/2/3/d
Obviously, you can do something like this:
Hope this helps.