Objective
Assign HTTP status code and date from cURL output to RESP and DATE variables using one-liner command.
Expectation
[08 Nov 2017 19:28:44 GMT] 301
Reality
$ read -d "\n" RESP DATE <<< $(curl -sv https://google.com 2>&1 | egrep -i "< HTTP/2|< Date" | sed "s/< HTTP\/2 //;s/< date: //g"); echo "[$DATE] $RESP"
[
] 30108 Nov 2017 19:28:44 GMT
$
EDIT:
Here's the full working command:
$ read -d "\r" RESP DATE <<< $(curl -sv https://google.com 2>&1 | tr -d "\r" | egrep -i "< HTTP/2|< Date" | sed "s/< HTTP\/2 //;s/< date: //g"); echo "[$DATE] $RESP"
[Wed, 08 Nov 2017 19:57:33 GMT] 301
$