Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
%x{ echo hi }
似乎分叉了/bin/sh。我宁愿/bin/bash. 有没有办法设置它?我能想到的最好的事情是
/bin/sh
/bin/bash
%x {/bin/bash -c 'echo hi'}
但这并不能像它应该的那样报告输出。此外,这是一件普遍的事情:我只是从不想要/bin/sh,我一直想要/bin/bash
把它写在你的 Ruby 代码的某个地方。
ENV["SHELL"] = "/bin/bash"
我希望默认 shell/bin/sh是硬编码的,以便尽可能便携。要使用 bash,您可以执行以下操作:
def bash(cmd) IO.popen(["/bin/bash", "-c", cmd]) {|io| io.read} end output = bash %q(cat <<< "hello world") p output
"hello world\n"