QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 4288|回复: 2

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

[复制链接]
发表于 2004-4-15 23:31:08 | 显示全部楼层 |阅读模式
小弟今天做了一个定时关机的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
发表于 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
回复

使用道具 举报

 楼主| 发表于 2004-4-17 21:48:13 | 显示全部楼层
是这样的啊,和C的逻辑差不多啊
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-11-6 19:18 , Processed in 0.040591 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表