nuoritoveri
nuoritoveri

Reputation: 2544

Wrong status value from bash script

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?

Upvotes: 3

Views: 191

Answers (1)

nuoritoveri
nuoritoveri

Reputation: 2544

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

Upvotes: 8

Related Questions