public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Calling cygpath from find exec?
@ 2015-11-23 21:14 Matt D.
  2015-11-23 21:16 ` Nellis, Kenneth
  2015-11-23 22:31 ` Eric Blake
  0 siblings, 2 replies; 5+ messages in thread
From: Matt D. @ 2015-11-23 21:14 UTC (permalink / raw)
  To: cygwin

Is there a reason why these produce different results?

find . -exec cygpath -wa {} \;
find . -exec echo $(cygpath -wa {}) \;

I have to do this which is much slower:
find . -exec bash -c 'echo $(cygpath -wa {})' \;

Or this:
find . | while read a; do echo $(cygpath -wa $a); done


Matt D.

--
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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: Calling cygpath from find exec?
  2015-11-23 21:14 Calling cygpath from find exec? Matt D.
@ 2015-11-23 21:16 ` Nellis, Kenneth
  2015-11-23 22:31 ` Eric Blake
  1 sibling, 0 replies; 5+ messages in thread
From: Nellis, Kenneth @ 2015-11-23 21:16 UTC (permalink / raw)
  To: cygwin

From: Matt D.
> 
> Is there a reason why these produce different results?
> 
> find . -exec cygpath -wa {} \;
> find . -exec echo $(cygpath -wa {}) \;
> 
> I have to do this which is much slower:
> find . -exec bash -c 'echo $(cygpath -wa {})' \;
> 
> Or this:
> find . | while read a; do echo $(cygpath -wa $a); done

How about the following?

find . | cygpath -waf-

--Ken Nellis

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Calling cygpath from find exec?
  2015-11-23 21:14 Calling cygpath from find exec? Matt D.
  2015-11-23 21:16 ` Nellis, Kenneth
@ 2015-11-23 22:31 ` Eric Blake
  2015-12-01 20:43   ` Duncan Roe
  1 sibling, 1 reply; 5+ messages in thread
From: Eric Blake @ 2015-11-23 22:31 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 888 bytes --]

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).

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Calling cygpath from find exec?
  2015-11-23 22:31 ` Eric Blake
@ 2015-12-01 20:43   ` Duncan Roe
  2015-12-01 20:52     ` Eric Blake
  0 siblings, 1 reply; 5+ messages in thread
From: Duncan Roe @ 2015-12-01 20:43 UTC (permalink / raw)
  To: cygwin

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: Calling cygpath from find exec?
  2015-12-01 20:43   ` Duncan Roe
@ 2015-12-01 20:52     ` Eric Blake
  0 siblings, 0 replies; 5+ messages in thread
From: Eric Blake @ 2015-12-01 20:52 UTC (permalink / raw)
  To: cygwin

[-- Attachment #1: Type: text/plain, Size: 636 bytes --]

On 12/01/2015 01:43 PM, Duncan Roe wrote:

>> 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.

But so does 'find ... -exec ... {} +', and with one fewer process.
xargs is fine when you need it, but here, you don't.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-12-01 20:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-23 21:14 Calling cygpath from find exec? Matt D.
2015-11-23 21:16 ` Nellis, Kenneth
2015-11-23 22:31 ` Eric Blake
2015-12-01 20:43   ` Duncan Roe
2015-12-01 20:52     ` Eric Blake

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).