# How to provide variable to irb session

**URL:** <https://rubytalk.org/t/how-to-provide-variable-to-irb-session/49180>\
**Category:** ruby-talk\
**Created:** [19 September 2008 16:14 UTC](https://rubytalk.org/t/how-to-provide-variable-to-irb-session/49180 "2008-09-19T16:14:14Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bryan\_Richardson1](https://avatars.discourse-cdn.com/v4/letter/b/e99b99/32.png) [@Bryan\_Richardson1](https://rubytalk.org/u/Bryan_Richardson1)\
**Post date:** [19 September 2008 16:14 UTC](https://rubytalk.org/t/how-to-provide-variable-to-irb-session/49180/1 "2008-09-19T16:14:14Z")

</div>

Hello all,

Can anyone tell me how I would go about providing a variable to an irb  
session? For example, see the following screenshot from the Metasploit  
Meterpreter in irb mode.

[http://www.metasploit.com/images/gallery/msf3-meterp-irb.jpg](http://www.metasploit.com/images/gallery/msf3-meterp-irb.jpg)

Does anyone know how they are actually providing the 'client' variable  
to the irb session?

> **···**
>
> --  
> Thanks!  
> Bryan  
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![TPReal](https://avatars.discourse-cdn.com/v4/letter/t/e68b1a/32.png) [@TPReal](https://rubytalk.org/u/TPReal)\
**Post date:** [19 September 2008 17:21 UTC](https://rubytalk.org/t/how-to-provide-variable-to-irb-session/49180/2 "2008-09-19T17:21:17Z")

</div>

Bryan Richardson wrote:

> Hello all,
> 
> Can anyone tell me how I would go about providing a variable to an irb  
> session? For example, see the following screenshot from the Metasploit  
> Meterpreter in irb mode.
> 
> [http://www.metasploit.com/images/gallery/msf3-meterp-irb.jpg](http://www.metasploit.com/images/gallery/msf3-meterp-irb.jpg)
> 
> Does anyone know how they are actually providing the 'client' variable  
> to the irb session?
> 
> --  
> Thanks!  
> Bryan

You can run your script at Ruby startup by specifying env variables  
([Ruby (Al2O3::Cr)](http://al2o3-cr.blogspot.com/2008/09/class-array.html), scroll to Add to  
load path), or you can specify env variable IRBRC pointing to a Ruby  
file that will be executed at the start of irb only.

TPR.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Brian\_Candler](https://avatars.discourse-cdn.com/v4/letter/b/5f9b8f/32.png) [@Brian\_Candler](https://rubytalk.org/u/Brian_Candler)\
**Post date:** [19 September 2008 19:48 UTC](https://rubytalk.org/t/how-to-provide-variable-to-irb-session/49180/3 "2008-09-19T19:48:20Z")

</div>

Bryan Richardson wrote:

> Hello all,
> 
> Can anyone tell me how I would go about providing a variable to an irb  
> session? For example, see the following screenshot from the Metasploit  
> Meterpreter in irb mode.
> 
> [http://www.metasploit.com/images/gallery/msf3-meterp-irb.jpg](http://www.metasploit.com/images/gallery/msf3-meterp-irb.jpg)
> 
> Does anyone know how they are actually providing the 'client' variable  
> to the irb session?

Is it definitely a variable, not a method?

This post shows how to start an IRb session within the context of an  
arbitary object:  
[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/244139](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/244139)

So you can create your own object class with a "client" method, create  
an instance of this object, and start IRb such that "self" is this  
object.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Tod\_Beardsley](https://avatars.discourse-cdn.com/v4/letter/t/41988e/32.png) [@Tod\_Beardsley](https://rubytalk.org/u/Tod_Beardsley)\
**Post date:** [19 September 2008 18:15 UTC](https://rubytalk.org/t/how-to-provide-variable-to-irb-session/49180/4 "2008-09-19T18:15:12Z")

</div>

A cheaty way:

[http://snippets.dzone.com/posts/show/6099](http://snippets.dzone.com/posts/show/6099)

> **···**
>
> On Fri, Sep 19, 2008 at 12:21 PM, Thomas B. \<tpreal@gmail.com\> wrote:
> 
> > Bryan Richardson wrote:
> > 
> > > Hello all,
> > > 
> > > Can anyone tell me how I would go about providing a variable to an irb  
> > > session? For example, see the following screenshot from the Metasploit  
> > > Meterpreter in irb mode.
> > > 
> > > [http://www.metasploit.com/images/gallery/msf3-meterp-irb.jpg](http://www.metasploit.com/images/gallery/msf3-meterp-irb.jpg)
> > > 
> > > Does anyone know how they are actually providing the 'client' variable  
> > > to the irb session?
> > > 
> > > --  
> > > Thanks!  
> > > Bryan
> > 
> > You can run your script at Ruby startup by specifying env variables  
> > ([Ruby (Al2O3::Cr)](http://al2o3-cr.blogspot.com/2008/09/class-array.html), scroll to Add to  
> > load path), or you can specify env variable IRBRC pointing to a Ruby  
> > file that will be executed at the start of irb only.
> > 
> > TPR.  
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
> 
> --  
> todb@planb-security.net | ICQ: 335082155 | Note: Due to Google's  
> privacy policy \<[http://tinyurl.com/5xbtl&gt](http://tinyurl.com/5xbtl&gt); and the United States'  
> policy on electronic surveillance \<[http://tinyurl.com/muuyl&gt;](http://tinyurl.com/muuyl&gt;),  
> please do not IM/e-mail me anything you wish to remain secret.

---

<div class="post-metadata">

**Author:** ![Bryan\_Richardson](https://avatars.discourse-cdn.com/v4/letter/b/b5ac83/32.png) [@Bryan\_Richardson](https://rubytalk.org/u/Bryan_Richardson)\
**Post date:** [19 September 2008 19:34 UTC](https://rubytalk.org/t/how-to-provide-variable-to-irb-session/49180/5 "2008-09-19T19:34:51Z")

</div>

Sweet... thanks!

> **···**
>
> On Fri, Sep 19, 2008 at 12:15 PM, Tod Beardsley \<todb@planb-security.net\> wrote:
> 
> > A cheaty way:
> > 
> > [http://snippets.dzone.com/posts/show/6099](http://snippets.dzone.com/posts/show/6099)
> > 
> > On Fri, Sep 19, 2008 at 12:21 PM, Thomas B. \<tpreal@gmail.com\> wrote:
> > 
> > > Bryan Richardson wrote:
> > > 
> > > > Hello all,
> > > > 
> > > > Can anyone tell me how I would go about providing a variable to an irb  
> > > > session? For example, see the following screenshot from the Metasploit  
> > > > Meterpreter in irb mode.
> > > > 
> > > > [http://www.metasploit.com/images/gallery/msf3-meterp-irb.jpg](http://www.metasploit.com/images/gallery/msf3-meterp-irb.jpg)
> > > > 
> > > > Does anyone know how they are actually providing the 'client' variable  
> > > > to the irb session?
> > > > 
> > > > --  
> > > > Thanks!  
> > > > Bryan
> > > 
> > > You can run your script at Ruby startup by specifying env variables  
> > > ([Ruby (Al2O3::Cr)](http://al2o3-cr.blogspot.com/2008/09/class-array.html), scroll to Add to  
> > > load path), or you can specify env variable IRBRC pointing to a Ruby  
> > > file that will be executed at the start of irb only.
> > > 
> > > TPR.  
> > > --  
> > > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
> > 
> > --  
> > todb@planb-security.net | ICQ: 335082155 | Note: Due to Google's  
> > privacy policy \<[http://tinyurl.com/5xbtl&gt](http://tinyurl.com/5xbtl&gt); and the United States'  
> > policy on electronic surveillance \<[http://tinyurl.com/muuyl&gt;](http://tinyurl.com/muuyl&gt;),  
> > please do not IM/e-mail me anything you wish to remain secret.
