如何传递ruby脚本';是否使用命令替换将输出作为shell命令的参数?
我在a_script.rb中有以下内容:如何传递ruby脚本';是否使用命令替换将输出作为shell命令的参数?,ruby,escaping,command-substitution,Ruby,Escaping,Command Substitution,我在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", "st
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"]
但是,我希望得到以下输出:
["string_without_spaces", "'string", "with", "spaces'"]
["string_without_spaces", "string with spaces"]
如何更改脚本以获得所需的输出?问题在于bash命令。Backtick正在转义
“
和”
您可以使用xargs
ruby a_script.rb | xargs ruby a_script.rb
我在书中找到了更令人信服的细节