Short, simple command to create a group if it doesn't already exist?

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.

Asked By: Oleg

getent group somegroupname || groupadd somegroupname
Answered By: glenn jackman

With force it exits successfully if the group already exists, and cancels -g if the GID is already used.

groupadd -f somegroupname
Answered By: ram4nd
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.