I'm writing a script where I am running curl commands several times. The use of the curl command varies throughout the script and I would like to save myself time (in the future when I have to debug the script) by using a variable to substitute a part of of the command that would be reused several times.
Example of a script that uses curl command curl -g -x "" -k
several times, but differently
# Usage 1
curl -g -x "" -k http://www.example.com/rest/v1/blah
# Usage 2
curl -g -x "" -k -i -X POST -H "Content-Type:application/json" -d "{'Username':'sally','Password':'password'}" http://www.example.com/rest/v1/blahblah
I would like to rewrite the above script using a variable for curl -g -x "" -k
# Snippet of curl command that will be used several times in script
curl_command="curl -g -x \"\" -k"
# Usage 1
$curl_command http://www.example.com/rest/v1/blah
# Usage 2
$curl_command -i -X POST -H "Content-Type:application/json" -d "{'Username':'sally','Password':'password'}" http://www.example.com/rest/v1/blahblah
Running the rewritten script results in an error:
curl: (5) Could not resolve proxy: ""; Name or service not known
For Usage 1, it appears to be executingcurl -g -x '""' -k http://www.example.com/rest/v1/blah
, resulting in the error shown above. I've tried assigning curl_command="curl -g -x '' -k"
and wrapping the variable in curly braces {} in the execution, but I get similar error. How can this be written to work?
Thanks in advance :)
""
as a the third element and instead takes-k
as the third element. The second one, wouldn't have helped me achieve my objective so I didn't try that one. Sorry for not following up sooner. – Sandy Nov 24 '15 at 23:26