user1787282 user1787282 - 6 months ago 18
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

Your code works

%x ("ls " + location)

Or

%x ("ls #{location}")