title: Getting output of curl command in a variable
body: <p>I need to fetch data out of a cloud platform. The process to export data is 2 step:</p>
  <ol>
  <li>First make a post call with the username/password details. This will return xml output with a jobid in the response.</li>
  <li>Fetch the jobid from the first response and use this jobid, concatenate it to get a new url and then make a get call (execute curl again) using this new url, I will then get data in a json response.</li>
  </ol>
  <p><strong>What I did:</strong>
  I am able to make the first API call and get the jobID. Next,I concatenated this jobId to get new url and saved complete curl statement in a variable (lets call the variable cmd_second_api_call). This variable 'cmd_second_api_call' contains the complete curl statement that I need to execute.
  So I did a out=$($cmd_second_api_call), as I want to execute the second curl statement and store the output in a variable.</p>
  <p><strong>Problem:</strong>
  When I execute out=$($cmd_second_api_call), I see out variable as empty. I verified $cmd_second_api_call actually outputs the curl command perfectly. If I execute the output of $cmd_second_api_call on my command prompt I see the output. What am I missing here? How to get the curl output in a variable?</p>
  <p>Thanks!</p>
  <pre><code>r=$(curl -k -u user:password static_url -d &lt;data I need to pass&gt;)
  
  jobid=$(echo $r | sed -n 's:.*&lt;jobid&gt;\(.*\)&lt;\/jobid&gt;.*:\1:p')
  
  second_url=&quot;abc.com/${jobid}/result/ --get -d output=json&quot;
  
  cmd_second_api_call=&quot;curl -u user:password -k ${second_url}&quot;
  
  out=$($cmd_second_api_call)
  
  echo $out
  </code></pre>