What is the cleanest way to modify this command in bash to only run if the group does not exist?
A one-liner would be best.
getent group somegroupname || groupadd somegroupname
[ $(getent group somegroupname) ] || groupadd somegroupname
Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).
id -u somegroupname &>/dev/null || groupadd somegroupname
since id -u somegroupname will return non-zero if it doesn't exist.
Sign up using Google
Sign up using Facebook
Sign up using Stack Exchange
3 months ago