user1787282 user1787282 - 1 year ago 88
Ruby Question

Add variable in %x command in ruby

I am trying to use the %x ( ) and use a variable that i've used earlier to determine a path of a file that i want to run.

essentially i want to do something like this

location = "/home/myhome/somefolder"
%x ("ls " + location)

Is there a way to do this?

Answer Source

Your code works

%x ("ls " + location)


%x ("ls #{location}")