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