# Defining a variable from the command prompt

**URL:** <https://www.ruby-forum.com/t/defining-a-variable-from-the-command-prompt/137970>\
**Category:** Ruby\
**Created:** [May 19, 2008, 4:05am UTC](https://www.ruby-forum.com/t/defining-a-variable-from-the-command-prompt/137970 "2008-05-19T04:05:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [May 19, 2008, 4:05am UTC](https://www.ruby-forum.com/t/defining-a-variable-from-the-command-prompt/137970/1 "2008-05-19T04:05:45Z")

</div>

hello,  
I have a script that sends emails out to my company, and I would like  
to be able to run it by saying (from the command prompt):

sendemail.rb “this is my message”

then it would take “this is my message” and use that as @msg or  
something. I know its possible, but I’m still pretty new to Ruby and not  
sure how to do this.

Any help is appreciated!

Thanks,

- Jeff M.

---

<div class="post-metadata">

**Author:** ![sithadmin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@sithadmin](https://www.ruby-forum.com/u/sithadmin)\
**Post date:** [May 19, 2008, 4:17am UTC](https://www.ruby-forum.com/t/defining-a-variable-from-the-command-prompt/137970/2 "2008-05-19T04:17:02Z")

</div>

# sendemail.rb “this is my message”

faq. research on ARGV

eg,

C:\family\ruby\>cat test.rb  
msg = ARGV[0] || “using default”  
puts msg

C:\family\ruby\>test.rb  
using default

C:\family\ruby\>test.rb “this is a test”  
this is a test

kind regards -botp
