Chinaunix

标题: 条件判断 [打印本页]

作者: tomasea    时间: 2011-06-27 10:20
标题: 条件判断
本帖最后由 tomasea 于 2011-06-27 10:29 编辑

现在又这样一个想法
有三个子条件需要同时成立才能满足要求,我想到可以这样
if [ ];then
  if [ ];then
     if [ ];then
      ....
      fi
   fi
fi


但是我想用另一种方法实现,比如
if [ 条件1 ];then
  flag1=1
else
  flag1=0
fi

if [ 条件2 ];then
  flag2=1
else
  flag2=0
fi

if [ 条件3 ];then
  flag3=1
else
  flag3=0
fi

FLAG=`echo flag1*flag2*flag3|bc`
if [ $FLAG -eq 1 ];then
...
else
....
fi

大家还有什么好方法没
作者: 267020090    时间: 2011-06-27 10:26
if [ ] && [ ] && []
作者: jason680    时间: 2011-06-27 10:29
现在又这样一个想法
有三个子条件需要同时成立才能满足要求,我想到可以这样
if [ ];then
  if [ ];then ...
tomasea 发表于 2011-06-27 10:20



man test

EXPRESSION1 -a EXPRESSION2
              both EXPRESSION1 and EXPRESSION2 are true
作者: yinyuemi    时间: 2011-06-27 10:31
本帖最后由 yinyuemi 于 2011-06-27 10:32 编辑

回复 1# tomasea


    if [ $(($flag1*$flag2*$flag3)) == 1 ]
or test  $(($flag1*$flag2*$flag3)) == 1  && {action}
作者: ryh19860922    时间: 2011-06-27 10:42
if [[ cond1 && cond2 && cond3 ]]
then
    action
fi
作者: 南极雨    时间: 2011-06-27 13:15
回复 1# tomasea


    case 语句..




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2