%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
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"
Write this somewhere in your Ruby code.
ENV["SHELL"] = "/bin/bash"