title: Substitute to an escaped shell string?
body: <p>I want to substitute ruby variable to an escaped shell string.</p>
  
  <p>This is what I start with, and it works:</p>
  
  <pre><code>&lt;&lt;~`SHELL`
    curl -s "#{CANVAS_URI}/api/v1/courses/#{COURSE_ID}/quizzes/#{quiz_id}/questions" \
      -X POST \
      -H "Content-Type: application/json" \
      -d '{ "question": { "question_type": "multiple_choice_question", "question_text": "&lt;p&gt;Is everything clear?&lt;/p&gt;", "points_possible": 1, "answers": [ { "text": "I read and understood", "html": "", "weight": 100 }, { "text": "I have questions", "comments_html": "&lt;p&gt;Please post your questions to a discussion (in course navigation).&lt;/p&gt;", "weight": 0 } ] } }' \
      -H "Authorization: Bearer #{CANVAS_TOKEN}"
  SHELL
  </code></pre>
  
  <p>However I want <code>discussion</code> (in a <code>-d JSON</code>) to be a link. And can't get it to work:</p>
  
  <pre><code>myJson = %Q|{ "question": { "question_type": "multiple_choice_question", "question_text": "&lt;p&gt;Is everything clear?&lt;/p&gt;", "points_possible": 1, "answers": [ { "text": "I read and understood", "html": "", "weight": 100 }, { "text": "I have questions", "comments_html": "&lt;p&gt;Please post your questions to a &lt;a href="#{CANVAS_URI}/courses/#{COURSE_ID}/discussion_topics"&gt;discussion&lt;/a&gt;.&lt;/p&gt;", "weight": 0 } ] } }|
  
  &lt;&lt;~`SHELL`
    curl -s "#{CANVAS_URI}/api/v1/courses/#{COURSE_ID}/quizzes/#{quiz_id}/questions" \
      -X POST \
      -H "Content-Type: application/json" \
      -d '#{myJson}' \
      -H "Authorization: Bearer #{CANVAS_TOKEN}"
  SHELL
  
  &lt;&lt;~`SHELL`
    curl -s "#{CANVAS_URI}/api/v1/courses/#{COURSE_ID}/quizzes/#{quiz_id}/questions" \
      -X POST \
      -H "Content-Type: application/json" \
      -d "#{myJson}" \
      -H "Authorization: Bearer #{CANVAS_TOKEN}"
  SHELL
  </code></pre>
  
  <p>I got trapped between escaping of the two langs.</p>
  
  <p>The whole thing is a workaround of posting nested json in ruby. Flat jsons works in most of the http gems, but getting nested json is a rare need, and I'm afraid most gems did not test against it (I remember trying http.rb to do this, but even json array are <a href="https://stackoverflow.com/a/46475686/788700">non trivial there</a>.</p>