linux - wget的返回值总是0

标签 linux bash centos wget

我正在尝试在 here 中使用以下已接受的答案,
例如做:

wget_output=$(wget -q google.com)
if [ $? -ne 0 ]; then
    echo "not zero"
else
    echo "zero"
fi

但无论站点是否存在/响应,我总是将 $? 的值设置为 0。 请指教

最佳答案

尝试缩小问题范围并直接使用 if 测试命令的返回值:

if wget http://www.google.com/badname
then echo 'true'
else echo 'not true'
fi

if wget http://www.google.com/index.html
then echo 'true'
else echo 'not true'
fi

关于linux - wget的返回值总是0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33001070/

相关文章:

xml - 从多个 xml 文件中提取节点

bash - 如何在管道中获取应用程序的错误代码?

linux - 如何列出Centos安装的第3方软件

linux - Centos 中的 Apache 用户权限

java - Fedora OpenJDK 设置 JAVA_HOME

c - 为什么我很困惑 "the exit status code is 0 when a command fails in BASH"

linux - rpmbuild:目录的共同所有权

linux - 将 bash 脚本作为守护进程运行

linux - 在 linux 中从配置文件中读取值

linux - 在用户空间中实现 Linux 字符驱动程序