1 |
Roy Marples wrote: |
2 |
|
3 |
> On Mon, 2007-10-15 at 10:43 +0200, Fabian Groffen wrote: |
4 |
>> On 15-10-2007 09:35:35 +0100, Roy Marples wrote: |
5 |
>> > find "${D}" -type f -name *${v}.*pm -delete |
6 |
>> |
7 |
>> Looks like you rely on your shell here to assume that you meant |
8 |
>> "*${v}.*pm" because there is nothing that matches that pattern by |
9 |
>> coincidence. If it does, your find probably doesn't do what you expect |
10 |
>> it to. |
11 |
> |
12 |
> It was like that in the original code snippet, I assumed that is what |
13 |
> the author intended? Anyway, you're probably right. |
14 |
> |
15 |
Well if portability is a concern, -delete is not specified in POSIX[1] |
16 |
afaict. -exec is, it turns out, including -exec blah {} + which really made |
17 |
me wonder why people still have such a thing for xargs. It turns out GNU |
18 |
didn't include this til recently, and it isn't in OpenBSD either for one[2] |
19 |
(..disgraceful, if you ask me ;) |
20 |
|
21 |
The unintended globbing is indeed unsafe, in the general case. I'd do this: |
22 |
|
23 |
find "$D" -type f -name '*'"$v"'.*pm' -exec rm {} + |
24 |
|
25 |
The shell will still treat that all as one argument (this method is |
26 |
typically used to insert variables into awk commands, or sed ones which |
27 |
use ".) The + will make the command execution more efficient for commands |
28 |
that take multiple filenames. The one caveat with + is that the {} must |
29 |
appear at the end of the command.[3] |
30 |
|
31 |
[1] http://www.opengroup.org/onlinepubs/009695399/utilities/find.html |
32 |
[2] |
33 |
http://www.openbsd.org/cgi-bin/man.cgi?query=find&apropos=0&sektion=1&manpath=OpenBSD+Current&arch=i386&format=html |
34 |
[3] http://wooledge.org/mywiki/UsingFind (highly recommended) |
35 |
|
36 |
|
37 |
-- |
38 |
gentoo-dev@g.o mailing list |