2016-06-19 3 views
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"] 

원하는 출력을 얻으려면 스크립트를 어떻게 변경합니까?

답변

2

문제는 bash 명령에 있습니다. 역 따옴표 내가 [이 댓글] 더 설득력 세부 사항을 발견 xargs

ruby a_script.rb | xargs ruby a_script.rb 
+0

당신은 (사용할 수있는 "'

을 탈출한다 http://unix.stackexchange.com/questions/24954/when-is- xargs-needed # comment33593_24956) –