简体   繁体   English

Shell脚本:如何检查多个组是否存在并在回显中显示

[英]Shell Script: how to check multiple groups if they exists and display in echo

This is my current code: 这是我当前的代码:

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

My questions are: 我的问题是:

  • how do I improve it by making it such that I can include more groups to display? 如何通过使其能够包括更多要显示的组来改进它?

  • and display the group eg administrators, appears in the echo like: The group administrators, students exists? 并显示组,例如管理员,在回显中显示为:组管理员,学生存在吗?

Use && to test multiple conditions. 使用&&测试多个条件。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM