nes1983
nes1983

Reputation: 15756

Use /bin/bash for %x in Ruby

%x{ echo hi } 

seems to fork off /bin/sh. I'd prefer /bin/bash. Is there a way to set that? The best thing I can think of is

%x {/bin/bash -c 'echo hi'}

but that doesn't to report output back like it should. Also, it's a general thing: I just never want /bin/sh, I always want /bin/bash

Upvotes: 1

Views: 1098

Answers (2)

glenn jackman
glenn jackman

Reputation: 247182

I expect the default shell /bin/sh is hardcoded in order to be as portable as possible. To use bash, you could do something like this:

def bash(cmd)
  IO.popen(["/bin/bash", "-c", cmd]) {|io| io.read}
end

output = bash %q(cat <<< "hello world")
p output
"hello world\n"

Upvotes: 1

sawa
sawa

Reputation: 168249

Write this somewhere in your Ruby code.

ENV["SHELL"] = "/bin/bash"

Upvotes: 3

Related Questions