[svlug] Working with spaces in shell scripts

Dale Harris rodmur at maybe.org
Tue Dec 14 15:52:12 PST 2004

On Tue, Dec 14, 2004 at 03:15:15PM -0800, Nathan elucidated:
> I want to remove the some files from inside a bunch of directories with
> spaces in the names. But when my script hits a directory with a space in
> its name the script will treat it as two separate directories (ie
> "Monkey Joe" becomes "Monkey" and "Joe"). Can this even be done with a
> shell script? Should I break down and use perl? 

You might take advantage of the  -print0 option to find which makes the
null char the delimiter than white space.

find . -print0 | grep -i monkey |  xargs --null rm -f

Or something like that.


More information about the svlug mailing list