title: Bash script curl
body: <pre><code>#!/bin/bash
  
  read -p 'Username: ' uservar
  read -p 'Password: ' passvar
  
  cacheVariable1="\"Content-Type:application/json"\"
  cacheVariable2="\"Cache-Control:no-cache"\"
  parametersVariable="'{\"username\":\"$uservar\",\"password\":\"$passvar\"}'"
  echo $parametersVariable
  echo $cacheVariable1 $cacheVariable2
  websiteVariable="https://example.com/session"
  
  echo $websiteVariable
  
  entireURL="curl -X POST -H "$cacheVariable1" -H "$cacheVariable2" -d "$parametersVariable" "$websiteVariable""
  
  echo "Entire URL IS: $entireURL"
  
  result=`$entireURL`
  
  
  echo "$result"
  </code></pre>
  
  <p>I want my script like this: curl -X POST -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{"username":"abc@abc.com", "password":"Password123"}' "<a href="https://example.com/session" rel="nofollow noreferrer">https://example.com/session</a>"</p>
  
  <p>Entire URL IS: curl -H "Content-Type:application/json" -H "Cache-Control:no-cache" -d '{"username":"zzzzzz","password":"azzzsass"}' <a href="https://cloud.tenable.com/session" rel="nofollow noreferrer">https://cloud.tenable.com/session</a></p>
  
  <p>But it does not execute in the bash. It gives me this error:</p>
  
  <pre><code>{"statusCode":400,"error":"Bad Request","message":"child \"username\" fails because [\"username\" is required]","validation":{"source":"payload","keys":["username"]}}
  </code></pre>
  
  <p>But it does not work. Can anyone help me?</p>
  
  <p>Update</p>
  
  <hr>
  
  <p>I solved it on my own. Everything was correct, except for executing as eval $entireURL. 
  Because A command embedded within a parenthesis runs as a sub-shell so my environment variables were missing.</p>