pinkme005 发表于 2004-4-15 23:31:08

shell最多支持多少重if嵌套啊,有没得像and or

小弟今天做了一个定时关机的shell,涉及到时间判定的问题,没有找到and or之类的逻辑语句,所用了多重if嵌套,但是语句通不过检测,请各位大虾帮忙看看啊!
shell如下:
#!/bin/sh
WEEK=`date +%H`
MINTE=`date +%M`
#the judge for hour
if $WEEK -gt 7
then
   echo"the time passed ,wait next time,halting    ..."
else
   if $WEEK -lt 6
    then
   echo"too early to start,have a good rest,system is halting ..."
      if $MINTE -gt 30
         then
          echo "the time is too late ,wait for the next time "
      fi
   fi
fi
if $WEEK -lt 11
   then
   echo"the time is not come,wait ...,system is halted..."
else
   if $WEEK -gt 13
    then
    echo "the time is lost ,the system is halting..."   
   fi
   if $MINTE -lt 30
   then
   echo "the time is too ealier,wait a moment"
fi
fi


if $WEEK -lt 17
   then
   echo"the time is not come,wait ...,system is halted..."
   if $MINTE -lt 30
      then
      echo "the is is too early,wait a moment..."
   fi
else
   if $WEEK -gt 18
   then
      echo "the time is over ,waiting for the system halting..."
      if $NINTE -gt 30
         then
          echo "the time is too late ,waiting for shutdwon..."
          fi
   fi
fi

if $WEEK -lt 21
   then
   echo"the time si not come,wait ...,system is halted..."
else
   if $WEEK -lt 23
   then
   echo"the time is ower ,waiting for the system halting..."   
   fi
fi

zq97_0 发表于 2004-4-17 10:14:52

and or之类的逻辑语句有:
字符:
if [ string1 -a string2 ] string1 and string2
if [ string1 -o string2 ] string1 or string2
关系:
if [ [ pattern1 && pattern2 ] ] pattern1 and pattern2
if [ [ pattern1 || pattern2 ] ] pattern1 or pattern2

pinkme005 发表于 2004-4-17 21:48:13

是这样的啊,和C的逻辑差不多啊
页: [1]
查看完整版本: shell最多支持多少重if嵌套啊,有没得像and or