From: Steve Pauly Date: 2010-07-02T10:56:56+09:00 Subject: Re: Running a shell command from ruby Brian Buckley wrote: >> #!/usr/bin/ruby >> script1=["touch ~/ruby/f1;touch ~/ruby/f2"] #addl array elements to >> be added >> puts script1[0].split(/;/) do |k| >> puts k >> system(k) >> end >> ---- > > >> The output from "puts k" looks good. > > Your block is not being called. I think the output you are seeing the is > from the first "puts", not the "puts" inside the block. > > You need to call "each" on the Array returned by split, like this: > > puts script1[0].split(/;/).each do |k| > puts k > system(k) > end > > --Brian Brian, you were right. Stupid of me not to think of the .each method. Thank you! Steve. revised script: script1=["touch /home/holocene/ruby/f1;touch /home/holocene/ruby/f2"] script1.length.times do |cnt| puts "script1 item #{cnt}" script1[0].split(/;/).each do |k| puts k system(k) end end -- Posted via http://www.ruby-forum.com/.