[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Automatic globbing of ARGV

Christian Madsen

9/27/2006 7:28:00 PM

I found a funny feature of Ruby tonight: if possible, commandline
arguments are automatically globbed. For instance in a directory with
one file foo.bar:

test.rb *.bar
=> ARGV = ['foo.bar']

test.rb *.html
=> ARGV = ['*.html']

Even the ** kind of globbing works.

I've tried to search google and the pickaxe book, but haven't found any
documentation on this feature.

Comments are appreciated.

-Christian

4 Answers

Paul Lutus

9/27/2006 7:37:00 PM

0

Christian Madsen wrote:

> I found a funny feature of Ruby tonight: if possible, commandline
> arguments are automatically globbed. For instance in a directory with
> one file foo.bar:
>
> test.rb *.bar
> => ARGV = ['foo.bar']
>
> test.rb *.html
> => ARGV = ['*.html']
>
> Even the ** kind of globbing works.
>
> I've tried to search google and the pickaxe book, but haven't found any
> documentation on this feature.

The globbing isn't happening in Ruby, it's happening in the shell that
launches Ruby.

In a directory with only foo.bar present, this will work:

$ echo *.bar

foo.bar

In a directory with many files, all will be globbed (except "." and ".."),
if you:

$ echo *

(long list)

This is standard shell behavior. It precedes execution of the command at the
left.

--
Paul Lutus
http://www.ara...

Ken Bloom

9/27/2006 11:01:00 PM

0

On Wed, 27 Sep 2006 12:27:55 -0700, Christian Madsen wrote:

> I found a funny feature of Ruby tonight: if possible, commandline
> arguments are automatically globbed. For instance in a directory with
> one file foo.bar:
>
> test.rb *.bar
> => ARGV = ['foo.bar']
>
> test.rb *.html
> => ARGV = ['*.html']

If a file matching the glob exists, then your shell globs it.
If a file matching the glob doesn't exist, then
* csh spits out an error message, always
* bash just passes the glob unchanged (as "*.html" here)


--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu...
I've added a signing subkey to my GPG key. Please update your keyring.

Christian Madsen

9/29/2006 3:46:00 AM

0

Just to clear things out, I am using win32.

So I created a test.c program:
void main(int argc, char *argv[])
{
int i;
for (i = 0; i < argc; i++)
printf("%s\n", argv[i]);
}

test.exe *.c
=> *.c

Which indicates that ruby does the globbing.

Finally, after looking into the ruby source, I can see that in fact,
ruby calls "ruby_globi" in win32.c. This also explains why dir-glob,
'**', worked.

-Christian

Ken Bloom skrev:
> On Wed, 27 Sep 2006 12:27:55 -0700, Christian Madsen wrote:
>
> > I found a funny feature of Ruby tonight: if possible, commandline
> > arguments are automatically globbed. For instance in a directory with
> > one file foo.bar:
> >
> > test.rb *.bar
> > => ARGV = ['foo.bar']
> >
> > test.rb *.html
> > => ARGV = ['*.html']
>
> If a file matching the glob exists, then your shell globs it.
> If a file matching the glob doesn't exist, then
> * csh spits out an error message, always
> * bash just passes the glob unchanged (as "*.html" here)
>
>
> --
> Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
> Department of Computer Science. Illinois Institute of Technology.
> http://www.iit.edu...
> I've added a signing subkey to my GPG key. Please update your keyring.

Dr Nic

9/29/2006 7:57:00 AM

0

Christian Madsen wrote:
> Finally, after looking into the ruby source, I can see that in fact,
> ruby calls "ruby_globi" in win32.c. This also explains why dir-glob,
> '**', worked.

So is it that Ruby on Win32 is covering for limitations of DOS/Cmd?
Nifty.

Nic

--
Posted via http://www.ruby-....