gpt4 book ai didi

linux - shell 脚本 : how to check multiple groups if they exists and display in echo

转载 作者:太空宇宙 更新时间:2023-11-04 12:46:30 25 4
gpt4 key购买 nike

这是我当前的代码:

 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

关于linux - shell 脚本 : how to check multiple groups if they exists and display in echo,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38552395/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com