I have a curl call:
curl --silent --connect-timeout 8 --output /dev/null http://0.0.0.0:5000/twi?c0=24 -I -w "%{http_code}\n" ``
It works fine and returns 200 if succeeded. I want the status code in a variable and tried:
curl --silent --connect-timeout 5 --output /dev/null http://0.0.0.0:5000/twi?c0=24
And then:
curl_status=$?
echo $curl_status
This call works well but gives 0 as $curl_status.
I tried:
curl_status=$(curl --silent --connect-timeout 5 --output /dev/null http://0.0.0.0:5000/twi?c0=24)
echo $curl_status
With the same result: call is executed, but gives 0 as $url_status.
Why do I not get the http_code of the first call into a variable to use in an if statement? I read many posts here with no success for a solution.
man curl.