# ARGV problems

**URL:** <https://rubytalk.org/t/argv-problems/9990>\
**Category:** ruby-talk\
**Created:** [3 February 2004 17:25 UTC](https://rubytalk.org/t/argv-problems/9990 "2004-02-03T17:25:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![tony\_summerfelt](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@tony\_summerfelt](https://rubytalk.org/u/tony_summerfelt)\
**Post date:** [3 February 2004 17:25 UTC](https://rubytalk.org/t/argv-problems/9990/1 "2004-02-03T17:25:12Z")

</div>

i seem to be having a problem with ARGV.

something as simple as this:

ARGV.each {|x| print “#{x}”}

prints: %\*

regardless of how many arguments i use.

what’s the proper way of getting commandline arguments. i was hoping to  
keep the code down by not using getoptlong, but i’ll use it if necessary

> **···**
>
> –  
> [http://home.cogeco.ca/~tsummerfelt1](http://home.cogeco.ca/~tsummerfelt1)

---

<div class="post-metadata">

**Author:** ![Sam\_Roberts1](https://avatars.discourse-cdn.com/v4/letter/s/ed8c4c/32.png) [@Sam\_Roberts1](https://rubytalk.org/u/Sam_Roberts1)\
**Post date:** [3 February 2004 17:48 UTC](https://rubytalk.org/t/argv-problems/9990/2 "2004-02-03T17:48:33Z")

</div>

It works for me...

[ensemble] ~/p/ruby $ ruby -e 'ARGV.each {|x| print "#{x}\n"}' aa bb cc  
aa  
bb  
cc

Can you give an example, or more context?

Cheers,  
Sam

Quoteing snowzone5@hotmail.com, on Wed, Feb 04, 2004 at 02:25:12AM +0900:

> **···**
>
> > i seem to be having a problem with ARGV.
> > 
> > something as simple as this:
> > 
> > ARGV.each {|x| print "#{x}"}
> > 
> > prints: %\*
> > 
> > regardless of how many arguments i use.
> > 
> > what's the proper way of getting commandline arguments. i was hoping to  
> > keep the code down by not using getoptlong, but i'll use it if necessary
> > 
> > --  
> > [http://home.cogeco.ca/~tsummerfelt1](http://home.cogeco.ca/~tsummerfelt1)

---

<div class="post-metadata">

**Author:** ![Mike\_Stok2](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@Mike\_Stok2](https://rubytalk.org/u/Mike_Stok2)\
**Post date:** [3 February 2004 19:30 UTC](https://rubytalk.org/t/argv-problems/9990/3 "2004-02-03T19:30:13Z")

</div>

In article [HFQTb.1317$\_62.501@read1.cgocable.net](mailto:HFQTb.1317$_62.501@read1.cgocable.net),

> i seem to be having a problem with ARGV.
> 
> something as simple as this:
> 
> ARGV.each {|x| print “#{x}”}
> 
> prints: %\*
> 
> regardless of how many arguments i use.
> 
> what’s the proper way of getting commandline arguments. i was hoping to  
> keep the code down by not using getoptlong, but i’ll use it if necessary

Is that your entire code?

[mike@ratdog tmp]$ cat try.rb  
#!/usr/bin/env ruby

ARGV.each {|x| puts “#{x}”}  
[mike@ratdog tmp]$ ./try.rb foo bar baz  
foo  
bar  
baz  
[mike@ratdog tmp]$

Mike

> **···**
>
> ## tony summerfelt [snowzone5@hotmail.com](mailto:snowzone5@hotmail.com) wrote:
> 
> [mike@stok.co.uk](mailto:mike@stok.co.uk) | The “`Stok’ disclaimers” apply.  
> [http://www.stok.co.uk/~mike/](http://www.stok.co.uk/~mike/) | GPG PGP Key 1024D/059913DA  
> [mike@exegenix.com](mailto:mike@exegenix.com) | Fingerprint 0570 71CD 6790 7C28 3D60  
> [http://www.exegenix.com/](http://www.exegenix.com/) | 75D2 9EC4 C1C0 0599 13DA

---

<div class="post-metadata">

**Author:** ![Gennady1](https://avatars.discourse-cdn.com/v4/letter/g/a4c791/32.png) [@Gennady1](https://rubytalk.org/u/Gennady1)\
**Post date:** [3 February 2004 19:45 UTC](https://rubytalk.org/t/argv-problems/9990/4 "2004-02-03T19:45:15Z")

</div>

Mike Stok wrote:

> In article [HFQTb.1317$\_62.501@read1.cgocable.net](mailto:HFQTb.1317$_62.501@read1.cgocable.net),
> 
> > i seem to be having a problem with ARGV.
> > 
> > something as simple as this:
> > 
> > ARGV.each {|x| print “#{x}”}
> > 
> > prints: %\*

I would make a wild guess that you call your ruby script from a shell  
script trying to pass it all command line parameters the sell script has  
been called with. In a shell script $\* stands for the entire command  
line, and it seems like you do %\* instead.

However if you use .bat files on Windows, where %\* is a correct way to  
specify all parameters, than it beats me.

Gennady.

> **···**
>
> > tony summerfelt [snowzone5@hotmail.com](mailto:snowzone5@hotmail.com) wrote:

---

<div class="post-metadata">

**Author:** ![tony\_summerfelt](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@tony\_summerfelt](https://rubytalk.org/u/tony_summerfelt)\
**Post date:** [3 February 2004 21:45 UTC](https://rubytalk.org/t/argv-problems/9990/5 "2004-02-03T21:45:11Z")

</div>

yup.

i AM using the new windows installer version of ruby (v1.8.1 (2004-01-07)  
that was just announced.

[checking older version (2004-01-27)].

ah ha…older version works fine…

i’d guess there’s something seriously wrong with the installer version 😕

> **···**
>
> On Tue, 03 Feb 2004 at 19:27 GMT, Mike Stok [mike@stok.co.uk](mailto:mike@stok.co.uk) wrote:
> 
> > Is that your entire code?
> 
> > ARGV.each {|x| puts “#{x}”}
> 
> –  
> [http://home.cogeco.ca/~tsummerfelt1](http://home.cogeco.ca/~tsummerfelt1)

---

<div class="post-metadata">

**Author:** ![tony\_summerfelt](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@tony\_summerfelt](https://rubytalk.org/u/tony_summerfelt)\
**Post date:** [3 February 2004 22:15 UTC](https://rubytalk.org/t/argv-problems/9990/6 "2004-02-03T22:15:04Z")

</div>

this was all from the command line.

on further investigation, my command shell is 4nt (nt version of 4dos) and  
just typing the program: argtest.rb aa bb

using a batch file it ran ok.

if i use the direct path to ruby g:\ruby\bin\ruby argtest.rb aa bb it  
works fine also…

> **···**
>
> On Tue, 03 Feb 2004 at 19:45 GMT, Gennady [gfb@tonesoft.com](mailto:gfb@tonesoft.com) wrote:
> 
> > I would make a wild guess that you call your ruby script from a shell  
> > script trying to pass it all command line parameters the sell script has i
> 
> –  
> [http://home.cogeco.ca/~tsummerfelt1](http://home.cogeco.ca/~tsummerfelt1)

---

<div class="post-metadata">

**Author:** ![Nobuyoshi\_Nakada](https://avatars.discourse-cdn.com/v4/letter/n/edb3f5/32.png) [@Nobuyoshi\_Nakada](https://rubytalk.org/u/Nobuyoshi_Nakada)\
**Post date:** [3 February 2004 23:38 UTC](https://rubytalk.org/t/argv-problems/9990/7 "2004-02-03T23:38:54Z")

</div>

Hi,

> **···**
>
> At Wed, 4 Feb 2004 07:15:04 +0900, tony summerfelt wrote:
> 
> > on further investigation, my command shell is 4nt (nt version of 4dos) and  
> > just typing the program: argtest.rb aa bb
> 
> Do you associate .rb to "g:\ruby\bin\ruby.exe %0 %_"? If so,  
> does 4nt really expand %_ in associated command lines?
> 
> –  
> Nobu Nakada

---

<div class="post-metadata">

**Author:** ![tony\_summerfelt](https://avatars.discourse-cdn.com/v4/letter/t/b9bd4f/32.png) [@tony\_summerfelt](https://rubytalk.org/u/tony_summerfelt)\
**Post date:** [4 February 2004 17:15 UTC](https://rubytalk.org/t/argv-problems/9990/8 "2004-02-04T17:15:04Z")

</div>

yes, actually i use .rb=“g:\ruby\bin\ruby.exe” and i had a typo

now of course it works 😕

that should be the last of the dumb questions i ask…for awhile… 🙂

> **···**
>
> On Tue, 03 Feb 2004 at 23:38 GMT, [nobu.nokada@softhome.net](mailto:nobu.nokada@softhome.net) wrote:
> 
> > Do you associate .rb to “g:\ruby\bin\ruby.exe %0 %\*”?
> 
> –  
> [http://home.cogeco.ca/~tsummerfelt1](http://home.cogeco.ca/~tsummerfelt1)
