簡體   English   中英

Wget的返回值始終為0

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM