Multiple and ors in if statement bash

前端 未结 2 1511
名媛妹妹
名媛妹妹 2021-01-20 06:17

Hi i am working on somoething , i need to create a if statement which will take multiple variables in \'&&\' and \'||\' combination . for now i am trying to this thi

2条回答
  •  醉梦人生
    2021-01-20 07:12

    In bash, you can do it like this:

    if [[ ( $pcount == 0  &&  $ucount == 0 ) || ( $flag == 1 ) ]]
    then
        echo "do stuff"
    fi
    

    Alternatively:

    if [ "$pcount" -eq 0 -a "$ucount" -eq 0 ] || [ "$flag" -eq 1 ]
    then
         echo "do stuff"
    fi
    

    But, I would recommend the first approach.

提交回复
热议问题