Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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:...
fi

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

Any idea?

share|improve this question

1 Answer 1

This should do the trick:

if groups | grep -w -q <GROUP_NAME>; then
  export PATH=$PATH:...
fi
share|improve this answer
1  
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

 
discard

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.