title: How to pass a double quoted value of a variable, as argument of the curl command, in a bash script?
body: <p>I have a script on a server whose last line is an echo which prints the value 
  of an URL something like this:</p>
  
  <pre><code>.
  .     &lt; the script code here &gt;
  .
  echo "url"      # The last line of this script
  </code></pre>
  
  <p>I don't have the possibility of changing this script and I can just 
  capture its return value, that is, capture the url as the return value 
  inside a variable declared in my local bash script, something like this:</p>
  
  <pre><code>cmd_url=$(ssh . . . &lt;distinct script&gt;)
  </code></pre>
  
  <p>Here is an example of such URL (for confidentiality reasons, of course 
  I changed the values)</p>
  
  <pre><code>http://mydomain:56789/cgi-bin/WebObjects/JavaMonitor.woa/admin/running?type=app&amp;name=AppTest&amp;pw=abcd&amp;9e0Xy
  </code></pre>
  
  <p>The above example is principally a WebObjects application info URL, which can be passed as an 
  argument of the curl command in order to know whether an application 
  is running (so the application name in this example is <strong>AppTest</strong> and the JavaMonitor 
  password that I have to provide in order to be able to query is <strong>abcd&amp;9e0Xy</strong>)</p>
  
  <p>If I open a terminal, I can simply paste this url <strong>enclosed within single quotes</strong> and 
  run the following</p>
  
  <pre><code>curl -s -X GET 'http://mydomain:56789/cgi-bin/WebObjects/JavaMonitor.woa/admin/running?type=app&amp;name=AppTest&amp;pw=abcd9e0Xy'
  </code></pre>
  
  <p>So I have to enclose the string within single quotes to escape special characters and that works pretty well, if the application AppTest is actually running then curl returns <strong>YES</strong>.</p>
  
  <p>Now what I need to do, is to do exactly what I wrote above except that it is done inside 
  a bash script and the url is not written manually enclosed within single quotes but 
  it is stored inside a variable.</p>
  
  <p>Here is what I do:</p>
  
  <pre><code>cmd_url=$(ssh . . . &lt;distant script&gt;)
  ret_msg=$(curl -s -X GET "$cmd_url")
  </code></pre>
  
  <p>And the problem is (I presume) due to the special characters in the URL. It seems that curl fails to 
  interpret the argument correctly. I even removed double quotes but that didn't
  solve the problem either.</p>
  
  <p>So my question is: how should I proceed ? How can I convert <strong>an already double quoted</strong> string 
  (recall that this is done on the distant server &amp; I cannot change that) to
  a single quoted string? So that curl would take it just as a sequence of characters 
  without interpreting them? like what I wrote above in the terminal example:</p>
  
  <pre><code>'http://mydomain:56789/cgi-bin/WebObjects/JavaMonitor.woa/admin/running?type=app&amp;name=AppTest&amp;pw=abcd9e0Xy'
  </code></pre>
  
  <p>So far I've tried different combinations of possible concatenation with single quotes 
  but the problem persists. Either curl doesn't return anything at all or I get an error message
  indicating the password has not been provided.</p>
  
  <p>Any idea? How can I pass an <strong>already double quoted</strong> local variable to curl in a bash script?</p>
  
  <p>Thanks in advance</p>