Skip to content
Advertisement

Error handling of user information in Unix

I need to do some error handling in the beginning of a script. If a user is not a member of a specific group then the script needs to exit.

Advertisement

Answer

group=wheel
if groups | grep -q "b$groupb"; then
  echo member
else
  echo "no member"
  exit 1
fi

or shorter:

group=wheel
groups | grep -q "b$groupb" || exit 1
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement