我正在尝试在 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/