0

here is two samples: this is a sample that would cause 400 error

curl -i -k -u $account:password -H "Content-Type: application/json" -X PUT -d '{"source-path": "http://${ip}/LTMBlackList_Postbody${filename_extension}","type":"ip"}' https://$ip2$api2

and this is a normal one, it can get a 200 OK response:

curl -i -k -u $account:$password -H "Content-Type: application/json" -X PUT -d '{"source-path": "http://127.0.0.1/LTMBlackList_Postbody-test.log","type":"ip"}' https://$ip2$api2

how could i called the curl command in script with variable?

Hsu Amanda
  • 31
  • 1
  • 1
  • 9
  • [Difference between single and double quotes in bash](https://stackoverflow.com/questions/6697753/difference-between-single-and-double-quotes-in-bash) – KamilCuk Mar 03 '20 at 12:12
  • I had also tried single and double quotes in the option, used another variable to indicate the option and combine them in the command. all trying cause the 400 response. – Hsu Amanda Mar 03 '20 at 12:16
  • ohhh i understand in the end!!! the devil hides in the details....thanks for your sharing!! – Hsu Amanda Mar 03 '20 at 12:25
  • Your title and question seem to have nothing to do with each other. – Paul Hodges Mar 03 '20 at 14:54
  • the context just list the example, the main question is described as the title. – Hsu Amanda Mar 04 '20 at 02:23

1 Answers1

1

The $ip is not expanded because it is in single quotes. First close single quotes then do double quotes, expand the variable, close double quotes and conitnue single quoting.

Remember to always quote your variable expansions to disable word splitting

curl -i -k -u "$account:$password" -H "Content-Type: application/json" -X PUT \
-d '{"source-path": "http:/'"$ip"'/LTMBlackList_Postbody'"$filename_extension"'","type":"ip"}' "https://$ip2$api"
KamilCuk
  • 120,984
  • 8
  • 59
  • 111
  • thanks for your advice! but I don't understand the rule of the order in the quotes, between double quotes and single quotes. and where can i learn these basic technologies? thanks for your response! – Hsu Amanda Mar 03 '20 at 12:21