I just sent this out, and then remembered that the fine people of use.perl have made good suggestions about this in the past, so here we go.
On Tuesday, Nov 26, 2002, at 11:36 Europe/London, Tatsuhiko Miyagawa wrote: >BTW, why not including a executable script to replace /usr/bin/find in >File::Find::Rule distribution? > > % findrule -type file -mp3 title="youth gone wild" -mp3 length="3min" /mp3 > % findrule -md5 blahblahblah /archives > % findrule -type file -image_x 120 It's a good idea, so I started on one yesterday[1]. Unfortunately I quickly hit on a problem of how to group without splitting arguments in a way that wouldn't be ideal. What I currently have is something that works like so: % findrule file name [ red blue ] # files called red or blue, below the current directory % findrule file name red blue # files called red, below the directory called blue But it kindof expects you to know what takes arguments (like name) and what doesn't (like file), which I'm not sure is so great. There's possibly adding - to indicate that you mean a clause, but then what if you really want to pass something starting with - as an argument. Hmmm. % findrule -file -name red blue # files called red or blue, below the current directory % findrule -file -name red -- blue # files called red, below the directory called blue % findrule -file -name -name # syntax error? I really wanted files called -name I'm more just thinking out loud right now, but if you have any suggestions I'd be glad to steal them from you. Thanks [1] http://mirth.unixbeard.net/svn/richardc/perl/File-Find-Rule/findrule -- Richard Clamp
I guess if you're building a workalike for unix find, you should follow the syntax used by that command (probably the GNU version, or maybe BSD if that's what floats your boat).
Either way, it's probably worth letting tomc know about your script, as the version of find currently on the Perl Power Tools site doesn't implement a lot of the find functionality.
% findrule -file -name red blue
# find files called red or blue, below the current directory
% findrule blue -file -name red
# find files called red, below the directory blue
Though I think it still leaves the ambiguity about finding things named -*, maybe we could use '[' ']' to disambiguate that (of course then we can't find things called '[' or ']'
% findrule -file -name [ -red ]
# find files called -red, below the current directory
If the -* is entered on the command line, in all Unices I've used, the shell will pre-populate the list. To get around it using "-*" will allow the string to be passed as an argument.
Sorry, I think you've taken my ramblings a bit too literally. I was talking of nailing down the meaning of -name -red
. If I apply a simple "things matching->name()->red()
, so how would I get to ->name( '-red' )
, which is what I really wanted.
Perhaps you could then specifically check for the wildcard character when reading the arguments and options, and deal with it appropriately.
File::Find::Rule->name quite happily copes with globbing patterns by delegating to Text::Glob, so we already have that one licked.
-name '"-red"'
Just to get around the shells quoting. Ewww.
-Dom
[ .. ]
as a shorthand for test ..
, so it would be unwise to use those characters.
Korn and Bash shells use [.. ] as a shorthand for test .., so it would be unwise to use those characters.
Odd, not from my the bash on my box, and not in a script either.[0]
This was giving me a little trouble before though, more for consistency with find(1) than anything, so I switched it over to using '(' and ')' as parameters. The hard part is finding a set of grouping characters that aren't significant in any shell, since () themselves are used by bash and zsh.
[0]
bash-2.05a$ ls [ foo ]
ls: [: No such file or directory
ls: ]: No such file or directory
foo
bash-2.05a$ cat foo
#!/bin/bash
ls [ foo ]
bash-2.05a$./foo
ls: [: No such file or directory
ls: ]: No such file or directory
foo