# Which shell?

**URL:** <https://www.ruby-forum.com/t/which-shell/181215>\
**Category:** Ruby\
**Created:** [January 7, 2010, 1:33pm UTC](https://www.ruby-forum.com/t/which-shell/181215 "2010-01-07T13:33:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![wybodekker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f05b48/32.png) [@wybodekker](https://www.ruby-forum.com/u/wybodekker)\
**Post date:** [January 7, 2010, 1:33pm UTC](https://www.ruby-forum.com/t/which-shell/181215/1 "2010-01-07T13:33:39Z")

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

---

<div class="post-metadata">

**Author:** ![wybodekker](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f05b48/32.png) [@wybodekker](https://www.ruby-forum.com/u/wybodekker)\
**Post date:** [January 7, 2010, 2:20pm UTC](https://www.ruby-forum.com/t/which-shell/181215/2 "2010-01-07T14:20:29Z")

</div>

On 01/07/2010 01:33 PM, Wybo D. wrote:

> How can I tel system to use bash?

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

robert
