Shell脚本:如何检查多个组(如果存在)并显示在echo中

时间:2016-07-24 13:09:53

标签: linux shell rhel7

这是我目前的代码:

 if [ $(getent group administrators) ]; then
   echo "Group exists"
 else
   echo "Group does not exist"
 fi

我的问题是:

  • 如何通过制作包含更多群组来改善它?

  • 并显示组,例如管理员,出现在echo中:组管理员,学生是否存在?

1 个答案:

答案 0 :(得分:0)

使用&&测试多个条件。

if [ $(getent group administrators) ] && [ $(getent group students) ]
then
    echo The groups administrators and students exit
else
    echo The groups administrators and students do not both exist
fi
相关问题