What is the cleanest way to modify this command in bash to only run if the group does not exist?
groupadd somegroupname
A one-liner would be best.
getent group somegroupname || groupadd somegroupname
[ $(getent group somegroupname) ] || groupadd somegroupname
Commented
Jul 18, 2014 at 20:06
With force it exits successfully if the group already exists, and cancels -g if the GID is already used.
groupadd -f somegroupname