Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. 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 have a customized PS1 to show several parameters. When I switch to a different group using newgrp, it switched my PS1 to default ($) and that is annoying. The default remains even when I switch back to my default group from the changed group.

Any way to stop it from doing that and just keep the PS1 I set in my .profile?

>uname -a
SunOS he2unx207 5.10 Generic_147440-19 sun4u sparc SUNW,Sun-Fire-880

Of course, if I resource my .profile after newgrp, the PS1 gets correctly applied but I am annoyed because newgrp effectively cancels what was set in .profile. Why can't it just change the effective group I am associated with without changing other settings?

share|improve this question
up vote 3 down vote accepted

If you export PS1, then the value shouldn't be reset. From the Solaris newgrp manpage:

Any variable that is not exported is reset to null or its default value. Exported variables retain their values. System variables (such as PS1, PS2, PATH, MAIL, and HOME), are reset to default values unless they have been exported by the system or the user. For example, when a user has a primary prompt string (PS1) other than $ (default) and has not exported PS1, the user's PS1 will be set to the default prompt string $, even if newgrp terminates with an error. Note that the shell command export (see sh(1) and set(1)) is the method to export variables so that they retain their assigned value when invoking new shells.

Alternatively, you can pass the - flag to newgrp to reinitialise the environment as if you had just logged in.

share|improve this answer
coincidentally, i noticed that my PS1 in fact was not being exported -- must have been a moment of absentmindedness as i normally always export all the vars set in my .profile. it works, thanks. – amphibient Oct 4 '12 at 16:30

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.