# Running linux command from inside

**URL:** <https://www.ruby-forum.com/t/running-linux-command-from-inside/109124>\
**Category:** Ruby\
**Created:** [July 11, 2007, 4:57pm UTC](https://www.ruby-forum.com/t/running-linux-command-from-inside/109124 "2007-07-11T16:57:10Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rorjeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rorjeff](https://www.ruby-forum.com/u/rorjeff)\
**Post date:** [July 11, 2007, 4:57pm UTC](https://www.ruby-forum.com/t/running-linux-command-from-inside/109124/1 "2007-07-11T16:57:10Z")

</div>

I’ve ran a search in ruby-talk but I couldn’t find an  
answer so…

Can I run a linux command inside a ruby program. Like

history  
=\> 63 history  
history -d63

Thanks  
Jeff B.

---

<div class="post-metadata">

**Author:** ![rorjeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rorjeff](https://www.ruby-forum.com/u/rorjeff)\
**Post date:** [July 11, 2007, 5:03pm UTC](https://www.ruby-forum.com/t/running-linux-command-from-inside/109124/2 "2007-07-11T17:03:10Z")

</div>

On 7/11/07, Jeffrey B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’ve ran a search in ruby-talk but I couldn’t find an  
> answer so…
> 
> Can I run a linux command inside a ruby program. Like
> 
> history  
> =\> 63 history  
> history -d63

You are probably looking for `` or Kernel#system.

for example: puts `ls /etc`

---

<div class="post-metadata">

**Author:** ![rorjeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rorjeff](https://www.ruby-forum.com/u/rorjeff)\
**Post date:** [July 11, 2007, 5:50pm UTC](https://www.ruby-forum.com/t/running-linux-command-from-inside/109124/3 "2007-07-11T17:50:17Z")

</div>

Hi,

Am Mittwoch, 11. Jul 2007, 23:55:29 +0900 schrieb Jeffrey B.:

> Can I run a linux command inside a ruby program. Like
> 
> history  
> =\> 63 history  
> history -d63

`history’ is not a Linux “command”, it is a Bash command.

What for do you need a command history when you’re not on a  
command line?

Bertram

---

<div class="post-metadata">

**Author:** ![rorjeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rorjeff](https://www.ruby-forum.com/u/rorjeff)\
**Post date:** [July 11, 2007, 6:07pm UTC](https://www.ruby-forum.com/t/running-linux-command-from-inside/109124/4 "2007-07-11T18:07:49Z")

</div>

Bertram S. wrote:

> Hi,
> 
> Am Mittwoch, 11. Jul 2007, 23:55:29 +0900 schrieb Jeffrey B.:
> 
> > Can I run a linux command inside a ruby program. Like
> > 
> > history  
> > =\> 63 history  
> > history -d63
> 
> `history’ is not a Linux “command”, it is a Bash command.
> 
> What for do you need a command history when you’re not on a  
> command line?
> 
> Bertram

Since it is a Bash specific command why can’t you just run a Bash  
command file using `` or system commands? That command file can contain  
the Bash specific invocaion commands in the first line or any other  
language for that matter. I don’t think it is a good idea to make your  
client aware of the specificity of the called program.

---

<div class="post-metadata">

**Author:** ![rorjeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rorjeff](https://www.ruby-forum.com/u/rorjeff)\
**Post date:** [July 11, 2007, 7:56pm UTC](https://www.ruby-forum.com/t/running-linux-command-from-inside/109124/5 "2007-07-11T19:56:09Z")

</div>

On Thu, Jul 12, 2007, Chris T. wrote:

> If you’re looking for a history inside of irb that you can play with, take a  
> look at something like  
> this[http://gilesbowkett.blogspot.com/2007/06/irbrc-modifications.html](http://gilesbowkett.blogspot.com/2007/06/irbrc-modifications.html)[http://gilesbowkett.blogspot.com/2007/06/irbrc-modifications.html](http://gilesbowkett.blogspot.com/2007/06/irbrc-modifications.html)but  
> make sure you get his new  
> version [http://pastie.caboo.se/71790](http://pastie.caboo.se/71790), as I found a tiny bug in the old  
> one. Handy for getting all the history you’ve done inside irb, or even  
> writing it out to a file so you can make a script out of it, etc.

Whoa, I never saw this. Kinda wish you guys had let me know 😉 No  
worries, though.

Thanks for the fixes. I needed to revisit this anyway, as there’s some  
other stuff that doesn’t work. I’ll contact you and Giles off-list  
about integrating your changes.

Ben

---

<div class="post-metadata">

**Author:** ![rorjeff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b9e5f3/32.png) [@rorjeff](https://www.ruby-forum.com/u/rorjeff)\
**Post date:** [July 11, 2007, 6:29pm UTC](https://www.ruby-forum.com/t/running-linux-command-from-inside/109124/6 "2007-07-11T18:29:21Z")

</div>

If you’re looking for a history inside of irb that you can play with,  
take a  
look at something like  
this[http://gilesbowkett.blogspot.com/2007/06/irbrc-modifications.html](http://gilesbowkett.blogspot.com/2007/06/irbrc-modifications.html)[http://gilesbowkett.blogspot.com/2007/06/irbrc-modifications.html](http://gilesbowkett.blogspot.com/2007/06/irbrc-modifications.html)but  
make sure you get his new  
version [http://pastie.caboo.se/71790](http://pastie.caboo.se/71790), as I found a tiny bug in the old  
one. Handy for getting all the history you’ve done inside irb, or even  
writing it out to a file so you can make a script out of it, etc.

Chris
