Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
add comment

1 Answer 1

up vote 2 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
add comment

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.