Shell脚本:如何检查多个组是否存在并在回显中显示
Shell Script: how to check multiple groups if they exists and display in echo
这是我当前的代码:
if [ $(getent group administrators) ]; then
echo "Group exists"
else
echo "Group does not exist"
fi
我的问题是:
如何改进它,使其可以包含更多要显示的组?
并显示组如administrators,在回显中出现:The group administrators, students exists?
使用&&
测试多个条件。
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
这是我当前的代码:
if [ $(getent group administrators) ]; then
echo "Group exists"
else
echo "Group does not exist"
fi
我的问题是:
如何改进它,使其可以包含更多要显示的组?
并显示组如administrators,在回显中出现:The group administrators, students exists?
使用&&
测试多个条件。
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