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.
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.
With force it exits successfully if the group already exists, and cancels -g if the GID is already used.
groupadd -f somegroupname
[ $(getent group somegroupname) ] || groupadd somegroupname
– Oleg Pryadko Jul 18 '14 at 20:06