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

We frequently sg to switch to a "shared" effective group. I want a visible reminder that we are not using our default group. Was thinking of having the bash prompt change color or display the effective group.

Any ideas how I should do this?

share|improve this question
up vote 2 down vote accepted

Add id -gn to PS1: E.g: export PS1='[\u@\h $(id -gn) \W]\$ ' can be placed in a bash profile file /etc/profile.d/

share|improve this answer
Will it work after issuing sg? I don't think so. – mailq Dec 9 '11 at 22:01
It does. I tested my answer. You need to put it in a bash profile as sg starts a new shell. – Mark Wagner Dec 10 '11 at 0:36
Then it's cool stuff. – mailq Dec 10 '11 at 0:39

Blatantly copying embobo's answer, you need to set up your $PROMPT_COMMAND bash variable, such as :

fran@orion ~ # export PROMPT_COMMAND='export PS1="[\u@\h $(id -gn) \W]\$ "'

fran@orion (20111209231004) ~ # 
fran@orion (20111209231005) ~ # 
fran@orion (20111209231006) ~ # 


share|improve this answer
You don't need to use $PROMPT_COMMAND as sg will start a new shell . – Mark Wagner Dec 10 '11 at 0:41

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.