How to check if grep has no output?

前端 未结 5 1369
借酒劲吻你
借酒劲吻你 2020-12-15 03:17

So I need to check if the recipient username is in /etc/passwd which contains all the users in my class, but I have tried a few different combinations of if statements and g

5条回答
  •  自闭症患者
    2020-12-15 03:25

    Just do a simple if like this:

    if grep -q $address  /etc/passwd
    then 
       echo "OK";
    else
       echo "NOT OK";
    fi
    

    The -q option is used here just to make grep quiet (don't output...)

提交回复
热议问题