In the ruby script it is necessary to execute bash code with the substitution of a rubish variable. How can I do that? Now I torment designs of a type:

test = "string" system 'echo $("#{test}")'

It is advisable not to take bash into a separate script with passing variables to it, but to execute it via system.

    2 answers 2

    So the argument for the system wrapped in single quotes. Interpolation will not work. It is necessary to wrap in double. Quotation marks inside either shield or replace with single ones:

     test = "here" system "echo \\'#{test}\\'" #=> 'here' system "echo \\\"#{test}\\\"" #=> "here" 

      You can use the usual interpolation #{} , just remember that it works either in double quotes,

       test = "string" system "echo '#{test}'" 

      or in the inverse (in this case, you can do without the system() method)

       test = 'ls -la' puts `#{test}`