【发布时间】:2014-07-07 13:34:51
【问题描述】:
我的 bash 脚本在内部运行 curl 命令。我想将 HTTP 响应代码作为脚本的状态返回。
我正在这样做:
statusCode=404
if [ $statusCode -ne 200 ]
then
echo $statusCode
exit $statusCode
fi
exit 0
状态码正确回显(404),但状态值($?)为148。我做错了什么?
【问题讨论】:
我的 bash 脚本在内部运行 curl 命令。我想将 HTTP 响应代码作为脚本的状态返回。
我正在这样做:
statusCode=404
if [ $statusCode -ne 200 ]
then
echo $statusCode
exit $statusCode
fi
exit 0
状态码正确回显(404),但状态值($?)为148。我做错了什么?
【问题讨论】:
这不可能通过 bash 脚本的 HTTP 响应代码退出,
因为 bash 脚本只能以 0-255 的值退出。
值404溢出变成148:
404 mod 256=148
【讨论】: