Friday, March 6, 2015

to test if a user is in a group


# isUserInGroup user group
function isUserInGroup {
  # \b is word boundary.
  if id -Gn ${1} | grep &>/dev/null "\b${2}\b"; then
    return 0 # true. exit status code

  return 1 # false exit status code

if ! isUserInGroup apache dev; then
  echo "The user is not in the group"
  echo "The user is in the group"

No comments: