I have a script like this:
for directory in $( find /afolder/ -maxdepth 1 -type d ); do
echo $directory
done
The problem is if I have a foldername with spaces in it such as "/afolder/this and that/" then it ends up splitting it into three variables, so the output is:
/afolder/this
and
that
When I really need the output to be:
/afolder/this\ and\ that
I've played around with find's output formatting options but I can't find anything to have it escape the space character.
for directory in $( find /afolder/ -maxdepth 1 -type d ); do
echo $directory
done
The problem is if I have a foldername with spaces in it such as "/afolder/this and that/" then it ends up splitting it into three variables, so the output is:
/afolder/this
and
that
When I really need the output to be:
/afolder/this\ and\ that
I've played around with find's output formatting options but I can't find anything to have it escape the space character.