2

我在 a_script.rb 中有以下内容:

if ARGV.empty?
    puts "string_without_spaces 'string with spaces'"
else
    p ARGV
end

当我运行时:

ruby a_script.rb `ruby a_script.rb`

我得到以下输出:

["string_without_spaces", "'string", "with", "spaces'"]

但相反,我希望得到以下输出:

["string_without_spaces", "string with spaces"]

如何更改脚本以获得想要的输出?

4

1 回答 1

2

问题出在您的 bash 命令中。反引号正在转义"'

您可以使用xargs

ruby a_script.rb | xargs ruby a_script.rb
于 2016-06-19T12:02:56.890 回答