checking wget's return value [if]

前端 未结 6 1771
离开以前
离开以前 2020-12-09 15:18

I\'m writing a script to download a bunch of files, and I want it to inform when a particular file doesn\'t exist.

r=`wget -q www.someurl.com`
if [ $r -ne 0          


        
6条回答
  •  旧时难觅i
    2020-12-09 15:36

    $r is empty, and therefore your condition becomes if [ -ne 0 ] and it seems as if -ne is used as a unary operator. Try this instead:

    wget -q www.someurl.com
    if [ $? -ne 0 ]
      ...
    

    EDIT As Andrew explained before me, backticks return standard output, while $? returns the exit code of the last operation.

提交回复
热议问题