Judas Iscariot
Judas Iscariot

Reputation: 83

How to pass a ruby script's output as arguments to a shell command using command substitution?

I have the following in a_script.rb:

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

When I run:

ruby a_script.rb `ruby a_script.rb`

I get the following output:

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

But instead, I would like to have the following output:

["string_without_spaces", "string with spaces"]

How do I change the script to get the wanted output?

Upvotes: 2

Views: 445

Answers (1)

Thomas
Thomas

Reputation: 1633

The problem is in your bash command. Backtick is escaping the " and '

You can use xargs

ruby a_script.rb | xargs ruby a_script.rb

Upvotes: 2

Related Questions