From: tamouse mailing lists Date: 2013-03-06T09:07:40+09:00 Subject: Re: telnet - how to loop through commands listed in a file On Tue, Mar 5, 2013 at 4:25 PM, Bob Ford wrote: > Bob Ford wrote in post #1100248: >> unknown wrote in post #1100227: >>> Am 05.03.2013 19:07, schrieb Bob Ford: >>>> Hmmm, The files are entered from the command line using a getopt (e.g -f >>>> "file1 file2 file3"). >>>> >>>> I'll look into this some more. Thank you. >>>> >>> >>> "file1 file2 file3".split >> >> I invoke this script from the commandline like such >> >> ruby TelnetCmds.rb -h 192.168.1.10 -f "C:\{PATH_TO_FILE}\File1 >> C:\{PATH_TO_FILE}|File2" >> >> I've been trying to convert that string to an array but I get the same >> error. >> >> filenames = "#{$file_arg}.split(" ")" > > I got it finally: > > filenames = "#{$file_arg}".split(/ /) > > Thank you for all the help!!! > > -- > Posted via http://www.ruby-forum.com/. > Just thinking: "#{$file_arg}" should be the same as $file_arg, no? You're getting strings from the command line parser, so the interpolation is unnecessary. This should suffice: filenames = $file_arg.split(/ /) assuming you're guaranteed one space between files. If it could be more than one, you'll want something like: filenames = $file_arg.split(/ +/) at the least. That's generally considered bad form (not sure whether the space and/or plus was deliberate), though, so better would be: filenames = $file_arg.split(/[ ]+/) Secondly, in Ruby, a $var is a global. You may not want that (true global variables should be rarer than hen's teeth).