[英]Wget's return value always get 0
我正在尝试在此处使用以下接受的答案,
例如做:
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
我试过了:
if wget -q google.com; then
并且现在似乎可以正常工作,如果该站点存在,那么它不为0且条件发生,否则为空且条件不发生。
你可以这样做:
URL="https://google.nl"
wget $URL --no-check-certificate -o /dev/null
if [ $? == 8 ]; then
echo "The site does'nt exist"
fi
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.