I have the following command that I execute from the shell:
curl -v -s -X GET -H "UserName: myUsername" -H "Password: myPassword"
https://example.com
and from terminal I have the HTTP/1.1 200 response with different response parameters:
HTTP/1.1 200 OK
Date: Fri, 23 Oct 2015 10:04:02 GMT
Name: myName
Age: myAge
...
Now, in my .sh file i want take name and age so have the values in my variables $name and $age. My initial idea was to redirect stdout to a file to parse:
curl -v -s -X GET -H "UserName: myUsername" -H "Password: myPassword"
https://example.com > out.txt
but the file is empty.
Some ideas to have a variables in bash script enhanced by the HTTP response?
EDIT: the variables that I want to take are in the header of the response
Thanks
You have to add --write-out '%{http_code}'
to the command line and curl will print the HTTP_CODE to stdout.
e.g.curl --silent --show-error --head http://some.url.com --user user:passwd --write-out '%{http_code}'
However I don't know all the other "variables" you can print out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With