[svlug] Working with spaces in shell scripts

Karsten M. Self kmself at ix.netcom.com
Tue Dec 14 21:30:01 PST 2004


on Tue, Dec 14, 2004 at 03:52:12PM -0800, Dale Harris (rodmur at maybe.org) wrote:
> 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.

    $ find . -name \*monkey\* -print0 | xargs -0 rm -f

...avoids the grep.


Peace.

-- 
Karsten M. Self <kmself at ix.netcom.com>        http://kmself.home.netcom.com/
 What Part of "Gestalt" don't you understand?
    KQED FM:  The DUMB spot on the dial:
    http://groups.google.com/groups?selm=rhpdc.95571%24gA5.1259567%40attbi_s03
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.svlug.org/archives/svlug/attachments/20041214/8cc0a325/attachment.bin


More information about the svlug mailing list