if循环语句的写法可以这样写吗?

请教一个脚本编程问题
if循环语句可以按照下面的写法吧?太久没用了,谢谢!

#!/bin/bash
#set -x
i2=`curl -s 20.40.30.57:9100/metrics |egrep "^check_ok" |awk '{print $2}'`
if [ $i2 == "1" ]
   then
      echo "1"
    else
        sleep 60 
        i3=`curl -s 20.40.30.57:9100/metrics |egrep "^check_ok" |awk '{print $2}'`
        if [ $i3 == "1" ]
           then
               echo "1"
           else
                sleep 60
                i4=`curl -s 20.40.30.57:9100/metrics |egrep "^check_ok" |awk '{print $2}'`
        fi
                if [ $i4 == "1" ]
                   then
                       echo "1"
                   else 
                        sleep 60
                        i5=`curl -s 20.40.30.57:9100/metrics |egrep "^check_ok" |awk '{print $2}'`
                fi
                        if [ $i5 == "1" ]
                           then 
                                 echo "1"
                           else
                                sleep 60
                                 i6=`curl -s 20.40.30.57:9100/metrics |egrep "^check_ok" |awk '{print $2}'`
                        fi
                                  if [ $i6 == "1" ]
                                     then
                                        echo "1"
                                     else 
                                        echo "0"
                                  fi

fi


你这个用一个循环不就行了?

#!/bin/bash
#set -x

for i in {1..5} ; do
    r=`echo -s 20.40.30.57:9100/metrics |egrep "^check_ok" |awk '{print $2}'`
    if [ "$r" == "1" ] ; then
        break
    else
        sleep 60
    fi
done
if [ "$r" == "1" ] ; then
    echo "1"
else
    echo "0"
fi

看着貌似没啥问题,你运行报错了?