I need to run a ruby script to compile and save a csv file, whose path will be determined by the ARGV I give the script. I want ruby to automatically open that file (using open filepath
inside backticks) at the end, but the filepath variable will be dynamic. How do I give the value of the filepath to the command inside backticks? Thank you!!
You can use string interpolation in backticks, just like with double quoted strings:
`open #{filepath}`
Side note: it’s a good idea to use Shellwords.escape
so that e.g. spaces inside filepath
won’t break your code:
require "shellwords"
`open #{Shellwords.escape(filepath)}`
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments