Using find results when directories have spaces in their names
bash, shell
Solution
The usual solution to this problem is:
find ... -print0 | xargs -0 ...
The `-print0` argument causes the output filenames to be nul-terminated and the `-0` / `-null` argument to xargs tells it to read such a format.
So in your case...
$ find . -type d -a -print0 | xargs -0 chmod 755
You don't actually need the shell loop at all.
Problem
I'm trying to change the permissions of all the subdirectories by making a simple bash `for` loop: ``` for dir in `find . -type d`; do chmod 755 "$dir"; done ``` however, it complains about non-existing directories. By simply printing the directory names from the loop (replacing `chmod 755 "$dir"` with `echo "$dir"`) I've worked out that the problem occurs when a directory has spaces in its name. What happens is that the `for` loop splits the results of `find` on every newline and space. I'd like to somehow make it split the results only according to newlines and ignore the spaces. The double quotes should make sure that the string reaches `chmod` as one argument. How do I change the splitting?