1833991 Members
3619 Online
110063 Solutions
New Discussion

Keeping PS1 same

 
SOLVED
Go to solution
Shivkumar
Super Advisor

Keeping PS1 same

Hello,

I am using PS1 environment variable in .profile to see servername and my home directories etc.

export PS1="$(uname -n)@$(whoami)\$PWD>"

But when i execute PowerBroker command to su to different user then this PS1 setting gets lost.

Is there a way to retain it even if i change to different user ?

Thanks,
Shiv
6 REPLIES 6
James R. Ferguson
Acclaimed Contributor
Solution

Re: Keeping PS1 same

Hi Shiv:

> But when i execute PowerBroker command to su to different user then this PS1 setting gets lost. Is there a way to retain it even if i change to different user ?

If you 'su - username' then you are sourcing the user's profile. This is going to reset or set its own PS1 environmental variable.

If you 'su username' _without_ the dash (hyphen) then 'su' does _not_ source the target user's profile, leaving your current environment unchanged.

See the 'su' manpages for more information.

Regards!

...JRF...
Shivkumar
Super Advisor

Re: Keeping PS1 same

In our PowerBroker setup looks like
'su-username' is mandatory. I just tried and it is not taking without "-".
Michael Mike Reaser
Valued Contributor

Re: Keeping PS1 same

Shiv:> In our PowerBroker setup looks like
'su - username' is mandatory. I just tried and it is not taking without "-".

If this is the case, then your PS1 value will be reset to whatever value the .profile and other login scripts for 'username' use for PS1. You cannot use the "-" for a login shell while *not* having the login scripts executed. The use of "-" on su will force PS1 to be changed if the other user's login scripts change it, period.
There's no place like 127.0.0.1

HP-Server-Literate since 1979
James R. Ferguson
Acclaimed Contributor

Re: Keeping PS1 same

Hi Shiv:

> In our PowerBroker setup looks like
'su-username' is mandatory. I just tried and it is not taking without "-".

You need to find out what environmental variables are needed in the target environment; place them in a stand-alone file; and source (read) them once you have switched users.

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: Keeping PS1 same

>JRF: You need to find out what environmental variables are needed in the target

Or the reverse, find out what sets PS1 and source that after you use PowerBroker.

For me, my PS1 is always "$ ". I have a pushd/popd functions that puts the directory path in the window title.
Avinash20
Honored Contributor

Re: Keeping PS1 same

Please add this variable in /etc/profile and make sure that PS1 variable is not defined in .profile of users.

This above setting will be set for all the users.

First /etc/profile executes and then .profile of user. Hence whatever defined in .profile will override variables defined in /etc/profile
"Light travels faster than sound. That's why some people appear bright until you hear them speak."