Username Username - 2 years ago 72
Ruby Question

How do I loop through elements of a bash array variable passed to a Ruby script via terminal?

I have a Bash file called

ruby testScript.rb $arr

And here's

ARGV.each{|a| p a}

When I run
in the terminal, I get this output:


I want my Ruby script to loop through all elements in the Bash array variable
. How do I fix my code to do this?

Answer Source

In the bash script, pass the array like this:

ruby testScript.rb ${arr[@]}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download