How do I expand a variable inside single quotes?
<p>I want to run this simple bash script:</p>

<pre><code>  curl https://www.googleapis.com/urlshortener/v1/url?key=MyKey -H \\
  'Content-Type: application/json' -d '{"longUrl": "$1"}'
</code></pre>

<p>but bash does not expand the <code>$1</code> because of the single quotes after <code>-d</code>. Google returns, expectedly, and error:</p>

<pre><code>{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "Invalid Value",
    "locationType": "parameter",
    "location": "resource.longUrl"
   }
  ],
  "code": 400,
  "message": "Invalid Value"
 }
}
</code></pre>

<p>How do I expand the <code>$1</code> inside the single quotes of the json object sent by <code>-d</code> in <code>curl</code>?</p>

<p>This question does seem to be a duplicate, but I cannot figure out the answer from the other ones. I'm providing the script in the hopes it will be useful for someone else as a contribution.</p>