title: How can I pass a variable to a system() call in ruby?
body: <p>Let's say I have a bunch of text in a variable, <code>some_var</code>, that could be pretty much anything.</p>
  
  <pre><code>some_var = "Hello, I'm a \"fancy\" variable | with a pipe, double- and single-quotes (terminated and unterminated), and more."
  </code></pre>
  
  <p>Let's also say that, in a CLI Ruby application, I want to allow the user to pipe that text into any Unix command. I've allowed them to input something like <code>some_var | espeak -a 200 -v en-us</code>, where the command to the right of the pipe is any unix CLI tool installed on their system.</p>
  
  <p>Let's also say that I already took care of separating the variable choice and the pipe out of their input, so I know for 100% certainty exactly what command is after the pipe. (In this case, I want to pipe the contents of the variable to <code>espeak -a 200 -v en-us</code>.)</p>
  
  <p>How would I do this? I don't think I can use the backtick method, or the <code>%x[]</code> literal. I've tried doing the following...</p>
  
  <pre><code>system("echo '#{some_var}' | espeak -a 200 -v en-us")
  </code></pre>
  
  <p>...but any special characters screw things up, and I can't remove the special characters. What should I do?</p>