Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to setup some environmental variables for all the users of a specific group. I can modify the .bash_profile of all the users in the group, but this does not work for future new users, hence I want to insert an if statement in /etc/profile of this kind:

if [`id -G` -eq GROUP_ID]; then
  export PATH=$PATH:...

But, I have problems because the users belong to more than one group.

Any idea?

share|improve this question

This should do the trick:

if groups | grep -w -q <GROUP_NAME>; then
  export PATH=$PATH:...
share|improve this answer
if you were going to do any sort of security based on that, I would be more particular about the check because echo "group1 group2 wikiroot" | grep root would match – Tom H May 31 '12 at 14:19
@TomH: You are perfectly right, I'm editing my answer. Adding -w to grep should solve that problem. – Oliver May 31 '12 at 14:21

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.