Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wrong status value from bash script

Tags:

http

bash

curl

My bash script runs curl command internally. I want to return the HTTP response code as the status of my script.

I'm doing this like here:

statusCode=404
if [ $statusCode -ne 200 ]
then
    echo $statusCode
    exit $statusCode
fi
exit 0

Status code is echoed properly (404), but status value ($?) is 148. What am I doing wrong?

like image 605
nuoritoveri Avatar asked Jun 18 '26 22:06

nuoritoveri


1 Answers

This is not possible to exit with HTTP response code from bash script, because bash script can only exit with values 0-255. Value 404 overflowed and turned into 148:

404 mod 256=148
like image 199
nuoritoveri Avatar answered Jun 20 '26 11:06

nuoritoveri



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!