[SGVLUG] bash "for" with spaces

Christopher Smith x at xman.org
Mon Apr 19 21:34:15 PDT 2010


That's the point where I want to think about engaging perl, but that said, in the particular case I'd do:

find . -type f -maxdepth 1 -print0 | grep -z -Z -l bar | xargs -0 foo

--Chris

On Apr 19, 2010, at 9:16 PM, "John E. Kreznar" <jek at ininx.com> wrote:

> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
>>> foo "$f"
> 
>> Where possible (and it is most often possible), the "find -print0 |
>> xargs -0" idiom works well too.
> 
> Very nice.  Thanks!  The cases where things seem to get baroque may be
> when the list is the result of a computation.  Example:
> 
>   for f in $(grep -l bar *) ; do foo $f ; done
> 
> where again, file names may contain blanks.  As I recall, I've been
> driven to fiddling with the IFS shell parameter.  Very messy.
> 
> - -- 
> John E. Kreznar jek at ininx.com 9F1148454619A5F08550 705961A47CC541AFEF13
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Processed by Mailcrypt 3.5.8+ <http://mailcrypt.sourceforge.net/>
> 
> iEYEARECAAYFAkvNKkkACgkQYaR8xUGv7xPt7wCePawIUHq+HwlDgezTA6z+p9Ou
> gpcAn0qITqGRcZdhrOD8gL5teNJoEwv3
> =6X47
> -----END PGP SIGNATURE-----
> 


More information about the SGVLUG mailing list