How can I make calls to the command line using the back tick and variables? Something like:
myvar = "C:\Program Files"
`cd ` + myvar
How can I make calls to the command line using the back tick and variables? Something like:
myvar = "C:\Program Files"
`cd ` + myvar
Also, consider using a system()
call, for clarity. Backticks are for short commands.
system
allows for a visually-more-obvious open + close block formatting that befits large, or multi-line OS instructions.
Though, if you're writing large OS scripts, put them in a shell file, check it into VCS, and exec that with a ruby one-liner.
Try this:
`cd "#{myvar}"`
Example:
$ irb --simple-prompt
>> `pwd`
=> "/home/kirti\n"
>> var = 'ruby'
=> "ruby"
>> `cd "#{var}" && pwd`
=> "/home/kirti/ruby\n"