<<< Date Index >>>     <<< Thread Index >>>

Re: [OT] Re: few questions



so spake Charles Cazabon [2004.07.07 @ 13:06]:
> Gary Johnson <garyjohn@xxxxxxxxxxxxxxx> wrote:
> > Don't you find that spaces in file names make it difficult to use a lot of
> > common Unix tools?  For example, this will try to execute grep on each word
> > of each file name containing spaces.
> > 
> >     find . -type f | xargs grep something
> 
> While I agree that spaces in filenames is a bad idea, this /specific/ example
> isn't a good illustration of it.  "Spaces-in-filenames" is exactly why
> find/xargs grew the -print0/-0 options (djb came up with the idea, and it's a
> darned good one), and would allow the above example to work correctly.

i never knew about the *0 options of find and xargs till today, (thanks
guys!) so i've always found other ways around the special characters in
filenames issue. 

for example, i've been known to use the following (albeit ugly) sed encantation
when filenames pose a problem : 

   find . -args | sed -e "s/\([ ,'?]\)/\\\\\1/g" | xargs blah

you can even write a quick shell script like:

   #!/bin/sh
   #safefind
   find "$@" | sed -e "s/\([ ,?']\)/\\\\\1/g"

which will allow one to bypass the (albeit convenient) *0 features of
find and xargs in a more concise fashion.  this would at least make 
downloading the gnu find utils not completely necessary - presuming sed
on that machine behaves in a similar fashion... ;)
-- 
 *------------------------*
//  ste\/e || 0x44288D05 //
*------------------------*

Attachment: pgpIvKBn6hlue.pgp
Description: PGP signature