我在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
。发生了什么事?
我在bash脚本中使用wget,然后检查退出代码以打印一些消息。那就是我的工作:wget -U mozilla -O my_page.html https://example.com/page echo $?有时我得到页面...
我检查了您的命令(稍作修改),对我来说,它很好用。
wget -U mozilla -O test.html https://google.com/ >>/dev/null 2>&1; echo $?
0