S.Smith S.Smith - 1 year ago 98
Bash Question

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"
echo "Group does not exist"

My questions are:

  • how do i improve it by making it such that i can include more groups to display?

  • and display the group e.g administrators, appears in the echo like: The group administrators, students exists?


Answer Source

Use && to test multiple conditions.

if [ $(getent group administrators) ] && [ $(getent group students) ]
    echo The groups administrators and students exit
    echo The groups administrators and students do not both exist
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download