Catkin, actually that grep will not work when LDAP is used.
The correct way to find out if a user exists is to run
If the user exists, it will output the username (same!). If the user does not exist, it will report an error.
(There is no group equivalent of
id although the C libraries do provide the
getgrnam() interface that provides the correct information, so checking if a group exists is trickier in a shell script. The way I'd do it, is create a temporary directory (with no access to anybody, mode 0). Then, if
env LANG=C LC_ALL=C chgrp 'group' dir 2>&1 returns something that contains
invalid group, then the group does not exist. It may return either nothing or an error, depending on whether the user is a member of that group or not. The directory is obviously removed immediately afterwards, and you do need to do this in a directory where you have write access, of course.)