# Which shell?

**URL:** <https://rubytalk.org/t/which-shell/56932>\
**Category:** ruby-talk\
**Created:** [7 January 2010 12:33 UTC](https://rubytalk.org/t/which-shell/56932 "2010-01-07T12:33:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wybo\_Dekker](https://avatars.discourse-cdn.com/v4/letter/w/ee59a6/32.png) [@Wybo\_Dekker](https://rubytalk.org/u/Wybo_Dekker)\
**Post date:** [7 January 2010 12:33 UTC](https://rubytalk.org/t/which-shell/56932/1 "2010-01-07T12:33:17Z")

</div>

It looks like Kernel#system uses sh, not bash, even though I told linux to use bash:

#!/usr/bin/env ruby  
system("echo $SHELL")  
system("ls -d /{etc,sbin}")

=\>

/bin/bash  
ls: cannot access /{etc,sbin}: No such file or directory

How can I tel system to use bash?

> **···**
>
> --  
> Wybo

---

<div class="post-metadata">

**Author:** ![Robert\_K1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/robert_k1/32/1830_2.png) [@Robert\_K1](https://rubytalk.org/u/Robert_K1)\
**Post date:** [7 January 2010 13:20 UTC](https://rubytalk.org/t/which-shell/56932/2 "2010-01-07T13:20:05Z")

</div>

If I would want to enforce a particular shell I would always explicit invoke it and not rely on the environment shell set appropriately (your script will otherwise break immediately if someone uses a different shell). Here's one way to do it:

robert@fussel:~$ ruby19 -e "system('bash','-c','ls -d /{etc,sbin}')"  
/etc /sbin

But you don't really need a shell for this. In your case you could as well do this:

robert@fussel:~$ ruby19 -e 'p Dir["/{etc,sbin}"]'  
["/etc", "/sbin"]

or even

robert@fussel:~$ ruby19 -e 'p %w{/etc /sbin}.select{|d| test ?d, d}'  
["/etc", "/sbin"]

or more verbose

robert@fussel:~$ ruby19 -e 'p %w{/etc /sbin}.select{|d| File.directory? d}'  
["/etc", "/sbin"]

...

I can't really think of a reason to fork a particular shell from a Ruby script other than for executing an existing shell script (in which case it is taken care of automatically provided you have the proper shebang line). All other tasks are probably done more efficiently from inside the interpreter.

Kind regards

&nbsp;&nbsp;robert

> **···**
>
> On 01/07/2010 01:33 PM, Wybo Dekker wrote:
> 
> > It looks like Kernel#system uses sh, not bash, even though I told linux to use bash:
> > 
> > #!/usr/bin/env ruby  
> > system("echo $SHELL")  
> > system("ls -d /{etc,sbin}")
> > 
> > =\>
> > 
> > /bin/bash  
> > ls: cannot access /{etc,sbin}: No such file or directory
> > 
> > How can I tel system to use bash?
> 
> --  
> remember.guy do |as, often| as.you\_can - without end  
> [http://blog.rubybestpractices.com/](http://blog.rubybestpractices.com/)
