# How to provide variable to irb session

**URL:** <https://www.ruby-forum.com/t/how-to-provide-variable-to-irb-session/149044>\
**Category:** Ruby\
**Created:** [September 19, 2008, 6:22pm UTC](https://www.ruby-forum.com/t/how-to-provide-variable-to-irb-session/149044 "2008-09-19T18:22:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![roxah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@roxah](https://www.ruby-forum.com/u/roxah)\
**Post date:** [September 19, 2008, 6:22pm UTC](https://www.ruby-forum.com/t/how-to-provide-variable-to-irb-session/149044/1 "2008-09-19T18:22:01Z")

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

---

<div class="post-metadata">

**Author:** ![roxah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@roxah](https://www.ruby-forum.com/u/roxah)\
**Post date:** [September 19, 2008, 7:29pm UTC](https://www.ruby-forum.com/t/how-to-provide-variable-to-irb-session/149044/2 "2008-09-19T19:29:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![roxah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@roxah](https://www.ruby-forum.com/u/roxah)\
**Post date:** [September 19, 2008, 8:23pm UTC](https://www.ruby-forum.com/t/how-to-provide-variable-to-irb-session/149044/3 "2008-09-19T20:23:39Z")

</div>

A cheaty way:

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

---

<div class="post-metadata">

**Author:** ![roxah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@roxah](https://www.ruby-forum.com/u/roxah)\
**Post date:** [September 19, 2008, 9:45pm UTC](https://www.ruby-forum.com/t/how-to-provide-variable-to-irb-session/149044/4 "2008-09-19T21:45:28Z")

</div>

Sweet… thanks!

---

<div class="post-metadata">

**Author:** ![roxah](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@roxah](https://www.ruby-forum.com/u/roxah)\
**Post date:** [September 19, 2008, 9:56pm UTC](https://www.ruby-forum.com/t/how-to-provide-variable-to-irb-session/149044/5 "2008-09-19T21:56:06Z")

</div>

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