【发布时间】:2020-01-23 18:10:23
【问题描述】:
我在 bash 脚本中使用 wget 并检查退出代码以打印一些消息。我就是这样做的:
wget -U mozilla -O my_page.html https://example.com/page
echo $?
有时我会成功获取页面,因为它存在,有时我会得到一个无效文件,因为 404 错误(页面不存在)。
嗯,我总是得到退出代码号4,在任何情况下。
wget 的手册页说明了 wget 退出代码:
0 No problems occurred.
1 Generic error code.
2 Parse error---for instance, when parsing command-line options, the .wgetrc or .netrc...
3 File I/O error.
4 Network failure.
5 SSL verification failure.
6 Username/password authentication failure.
7 Protocol errors.
8 Server issued an error response.
我希望在成功下载时获得代码 0,在收到 404 错误时获得代码 8。
发生了什么事?
【问题讨论】: