# Newbie's question: getting parameters given to hello.rb file

**URL:** <https://www.ruby-forum.com/t/newbies-question-getting-parameters-given-to-hello-rb-file/155078>\
**Category:** Ruby\
**Created:** [December 7, 2008, 3:16pm UTC](https://www.ruby-forum.com/t/newbies-question-getting-parameters-given-to-hello-rb-file/155078 "2008-12-07T15:16:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![maiwald](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/96bed5/32.png) [@maiwald](https://www.ruby-forum.com/u/maiwald)\
**Post date:** [December 7, 2008, 3:16pm UTC](https://www.ruby-forum.com/t/newbies-question-getting-parameters-given-to-hello-rb-file/155078/1 "2008-12-07T15:16:40Z")

</div>

hello,

given i have a programme “hello.rb” and i execute it in terminal like  
this

./hello.rb lalala lala stuff

how do i get the “lalala lala stuff” into my programme?

thanks

---

<div class="post-metadata">

**Author:** ![maiwald](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/96bed5/32.png) [@maiwald](https://www.ruby-forum.com/u/maiwald)\
**Post date:** [December 7, 2008, 3:34pm UTC](https://www.ruby-forum.com/t/newbies-question-getting-parameters-given-to-hello-rb-file/155078/2 "2008-12-07T15:34:15Z")

</div>

L. Maiwald wrote:

> hello,
> 
> given i have a programme “hello.rb” and i execute it in terminal like  
> this
> 
> ./hello.rb lalala lala stuff
> 
> how do i get the “lalala lala stuff” into my programme?
> 
> thanks

The arguments are in the ARGV array. ARGV[0] is the first argument,  
ARGV[1] the second, and so forth.

---

<div class="post-metadata">

**Author:** ![maiwald](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/96bed5/32.png) [@maiwald](https://www.ruby-forum.com/u/maiwald)\
**Post date:** [December 7, 2008, 3:43pm UTC](https://www.ruby-forum.com/t/newbies-question-getting-parameters-given-to-hello-rb-file/155078/3 "2008-12-07T15:43:32Z")

</div>

Tim H. wrote:

> The arguments are in the ARGV array. ARGV[0] is the first argument,  
> ARGV[1] the second, and so forth.

thank you!

---

<div class="post-metadata">

**Author:** ![maiwald](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/96bed5/32.png) [@maiwald](https://www.ruby-forum.com/u/maiwald)\
**Post date:** [December 9, 2008, 6:25pm UTC](https://www.ruby-forum.com/t/newbies-question-getting-parameters-given-to-hello-rb-file/155078/4 "2008-12-09T18:25:38Z")

</div>

L. Maiwald wrote:

> Tim H. wrote:
> 
> > The arguments are in the ARGV array. ARGV[0] is the first argument,  
> > ARGV[1] the second, and so forth.
> 
> thank you!

additionally, sometimes it’s helpful to know the number of arguments  
sent in with

ARGV.size

when my shell-style ruby scripts are dependent on arguments, i include a  
line at the top like this:

raise ‘usage: rubycat.rb file1 file2’ if ARGV.size == 0
