当我们运行 apt-get update 时,如果失败,应该返回一个非零错误代码,但在我的例子中它仍然是 0。见下文:
root@ubuntu-base:/home/user# apt-get update
Err http://security.ubuntu.com trusty-security InRelease
Err http://packages.siawai.com:8085 trusty InRelease
Err http://ppa.launchpad.net trusty InRelease
Err http://ppa.launchpad.net trusty Release.gpg
Could not resolve 'ppa.launchpad.net'
Err http://security.ubuntu.com trusty-security Release.gpg
Could not resolve 'security.ubuntu.com'
Err http://packages.siawai.com:8085 trusty Release.gpg
Could not resolve 'packages.siawai.com'
Err http://in.archive.ubuntu.com trusty InRelease
Err http://in.archive.ubuntu.com trusty-updates InRelease
Err http://in.archive.ubuntu.com trusty-backports InRelease
Err http://in.archive.ubuntu.com trusty Release.gpg
Could not resolve 'in.archive.ubuntu.com'
Err http://in.archive.ubuntu.com trusty-updates Release.gpg
Could not resolve 'in.archive.ubuntu.com'
Err http://in.archive.ubuntu.com trusty-backports Release.gpg
Could not resolve 'in.archive.ubuntu.com'
Reading package lists... Done
W: Failed to fetch http://in.archive.ubuntu.com/ubuntu/dists/trusty/InRelease
W: Failed to fetch http://in.archive.ubuntu.com/ubuntu/dists/trusty-updates/InRelease
W: Failed to fetch http://in.archive.ubuntu.com/ubuntu/dists/trusty-backports/InRelease
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/trusty-security/InRelease
W: Failed to fetch http://ppa.launchpad.net/ondrej/php/ubuntu/dists/trusty/InRelease
W: Failed to fetch http://packages.siawai.com:8085/repos/dists/trusty/InRelease
W: Failed to fetch http://security.ubuntu.com/ubuntu/dists/trusty-security/Release.gpg Could not resolve 'security.ubuntu.com'
W: Failed to fetch http://packages.siawai.com:8085/repos/dists/trusty/Release.gpg Could not resolve 'packages.siawai.com'
W: Failed to fetch http://ppa.launchpad.net/ondrej/php/ubuntu/dists/trusty/Release.gpg Could not resolve 'ppa.launchpad.net'
W: Failed to fetch http://in.archive.ubuntu.com/ubuntu/dists/trusty/Release.gpg Could not resolve 'in.archive.ubuntu.com'
W: Failed to fetch http://in.archive.ubuntu.com/ubuntu/dists/trusty-updates/Release.gpg Could not resolve 'in.archive.ubuntu.com'
W: Failed to fetch http://in.archive.ubuntu.com/ubuntu/dists/trusty-backports/Release.gpg Could not resolve 'in.archive.ubuntu.com'
W: Some index files failed to download. They have been ignored, or old ones used instead.
root@ubuntu-base:/home/user# echo $?
0
可能是什么问题?我运行的是 ubuntu 14.04。
答案1
这是故意的;看#778357:
结果是有意义的。 0 表示成功或暂时错误,而其他值表示持续错误。