I am using the following snippet of code to read file paths into an array;
files=()
while IFS= read -r -d $'\0'; do
files+=("$REPLY")
done < <(find $dir -type f -print0)
However, when I use print or echo to output each stored file path looping through the array, the spaces are output as normal. I would like to escape them.
some/path/to file -> some/path/to\ file
find "$dir", btw, or directory names with spaces will behave badly.cp "${files[1]}" "$targetdir") and it'll work correctly.