This is the mail archive of the
cygwin
mailing list for the Cygwin project.
Re: Calling cygpath from find exec?
- From: Duncan Roe <duncan_roe at acslink dot net dot au>
- To: cygwin at cygwin dot com
- Date: Wed, 2 Dec 2015 07:43:01 +1100
- Subject: Re: Calling cygpath from find exec?
- Authentication-results: sourceware.org; auth=none
- References: <56537B03 dot 4050204 at codespunk dot com> <565383D5 dot 3010709 at redhat dot com>
On Mon, Nov 23, 2015 at 02:23:33PM -0700, Eric Blake wrote:
> On 11/23/2015 01:45 PM, Matt D. wrote:
> > Is there a reason why these produce different results?
> >
> > find . -exec cygpath -wa {} \;
> > find . -exec echo $(cygpath -wa {}) \;
>
> Incorrect quoting. You are invoking:
>
> find . -exec echo c:\cygwin\home\you\{} \;
>
> (or whatever ./{} resolves to), instead of one cygpath per name found by
> find.
>
> >
> > I have to do this which is much slower:
> > find . -exec bash -c 'echo $(cygpath -wa {})' \;
> >
>
> This indeed quotes things so that cygpath is now invoked once per file,
> but at the expense of an additional bash per file as well.
>
> Why not just:
>
> find . -exec cygpath -wa {} +
>
> since cygpath handles more than one file in an invocation (that is,
> using '-exec {} +' rather than '-exec {} \;' is generally faster).
>
I would be using xargs. Especially under /cygdrive, the "-print0 / xargs -0"
combination takes care of spaces and other nasties in file names.
find . -print0 | xargs -0 cygpath -wa
For utilities that only accept one argument, you can use xargs -n1 -0; you
still get the benefit of -print0.
Cheers ... Duncan.
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple