# Automatic globbing of ARGV

**URL:** <https://www.ruby-forum.com/t/automatic-globbing-of-argv/70272>\
**Category:** Ruby\
**Created:** [September 27, 2006, 9:31pm UTC](https://www.ruby-forum.com/t/automatic-globbing-of-argv/70272 "2006-09-27T21:31:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmanruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@cmanruby](https://www.ruby-forum.com/u/cmanruby)\
**Post date:** [September 27, 2006, 9:31pm UTC](https://www.ruby-forum.com/t/automatic-globbing-of-argv/70272/1 "2006-09-27T21:31:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cmanruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@cmanruby](https://www.ruby-forum.com/u/cmanruby)\
**Post date:** [September 27, 2006, 9:41pm UTC](https://www.ruby-forum.com/t/automatic-globbing-of-argv/70272/2 "2006-09-27T21:41:58Z")

</div>

Christian M. wrote:

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

---

<div class="post-metadata">

**Author:** ![cmanruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@cmanruby](https://www.ruby-forum.com/u/cmanruby)\
**Post date:** [September 28, 2006, 1:06am UTC](https://www.ruby-forum.com/t/automatic-globbing-of-argv/70272/3 "2006-09-28T01:06:24Z")

</div>

On Wed, 27 Sep 2006 12:27:55 -0700, Christian M. 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)

---

<div class="post-metadata">

**Author:** ![cmanruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@cmanruby](https://www.ruby-forum.com/u/cmanruby)\
**Post date:** [September 29, 2006, 9:57am UTC](https://www.ruby-forum.com/t/automatic-globbing-of-argv/70272/4 "2006-09-29T09:57:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cmanruby](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/97f17d/32.png) [@cmanruby](https://www.ruby-forum.com/u/cmanruby)\
**Post date:** [September 29, 2006, 5:51am UTC](https://www.ruby-forum.com/t/automatic-globbing-of-argv/70272/5 "2006-09-29T05:51:01Z")

</div>

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 B. skrev:
