From: Craig Kim Date: 2006-04-06T10:37:14+09:00 Subject: Re: HOWTO Use Veriables inside of Regexp and Commands? To answer the original question, you can embedded any variables or expressions in #{exp}. In your example, you can say: directory = '/tmp' puts `ls #{directory}` if '/tmp/junk' =~ /^#{directory}/ If you are interested in getting directory entries, Keith's excellent suggestion is what you should consider. Hope it helps! -----Original Message----- From: Keith Sader [mailto:ksader@gmail.com] Sent: Wednesday, April 05, 2006 8:30 PM Have you tried just using Dir.entries('/path/to/dir').each {|entry| puts entry}? On 4/5/06, Karl Bennett wrote: > Hi, > > I've just started using Ruby and am LOVING IT! :D > > For my job I need to do allot of shell scripting but have been getting > very annoyed at its limitations. > > So I am now looking to Ruby to replace it. The thing is I need to be > able to run a command say "ls" with a variable say "directory". Heres an > example of what I would do in shell script. > > $directory="/tmp" > > ls $directory > > Now in Ruby I have to use the backquotes for commands right? So if I > create a variable directory in Ruby how do I get it's contents to be > executed in the command or evaluated in a regular expression? > > For example: > > directory = "/tmp" > > puts `ls directory` > puts /directory/ > > I know the above is wrong and both will just evaluate the word directory > not the variables contents. So how do I get the contents in there? > > Thank you very much for you help. > > -- > Posted via http://www.ruby-forum.com/. > > -- Keith Sader ksader@gmail.com http://www.saderfamily.org/roller/page/ksader