Operating System - HP-UX
1748177 Members
4509 Online
108758 Solutions
New Discussion юеВ

Re: changing command prompt dynamically

 
SOLVED
Go to solution
Shivkumar
Super Advisor

changing command prompt dynamically

Hi,

I have put the below line in my .profile.

export PS1="[`whoami`@`hostname`:`echo '$PWD'`]$ "

When i become root user i want to change the dollar prompt to "#"

Can someone suggest how to do it ?

Thanks,
Shiv
7 REPLIES 7
Rajeev  Shukla
Honored Contributor

Re: changing command prompt dynamically

Hi Shiv,
I think i didnt understand correctly..
1. When you become root user your prompt will surely change from $ to #, isn't that happening right now for you.
James R. Ferguson
Acclaimed Contributor

Re: changing command prompt dynamically

Hi Shiv:

IF you 'su' from your login account to root and do:

# su root

...then 'root's profile is not read and you will not see any change in your PS1 prompt.

If, on the otherhand you do:

# su - root

...then whatever the PS1 prompt is defined as in the '.profile' for 'root' is honored. By default, this will be a "#".

Regards!

...JRF...
Shivkumar
Super Advisor

Re: changing command prompt dynamically

Actually we are using powerbroker software to become privileged user (i.e. root user). I have changed my .profile as described in my first post. I become root by typing "$pbrun ksh" on the dollar prompt. Once i become root this dollar prompt remains the same. Once I become root, dollar prompt should become "#" automatically.

Thanks,
Shiv
James R. Ferguson
Acclaimed Contributor

Re: changing command prompt dynamically

Hi Shiv:

You said, "I become root by typing "$pbrun ksh". Shiv, unless you use 'su' to switch users and cause your profile to be sourced (read) you will need to provide substantially more information.

First, I am assuming that you are using the standard Poxix shell. Are you? Otherwise, you will need to change the "$pbrun" object to assign "#" to the PS1 environmental variable and export it when run.

Regards!

...JRF...
Shivkumar
Super Advisor

Re: changing command prompt dynamically

When i executed $env command as my normal login id it shows
"SHELL=/usr/bin/ksh". It means it is not posix shell. It has been set as korn shell.

Whenever i am logged in as normal user the command prompt should show "[sksonkar@servername:/home/sksonkar]$" and when i become privilaged user by typing $pbrun ksh it should change to "[sksonkar@servername:/home/sksonkar]$".

As i navigate to other directories the name of directory on the prompt should show the current one.

Regards,
Shiv
James R. Ferguson
Acclaimed Contributor

Re: changing command prompt dynamically

Hi Shiv:

As I said, the only way that you are going to transition to being a "superuser" is to execute an 'su' command.

I hope that there is only onle superuser (uid=0) on your server and that that is named "root" and has a default shell of '/sbin/sh' (the static Posix one!).

It would help greatly if you would post the 'pbrun' source, assuming that it is a command text file of some sort and not a binary.

Regards!

...JRF...
John Donovan
Regular Advisor
Solution

Re: changing command prompt dynamically

A quick search on the Symark support site, http://www.symark.com/powerbroker_faq.htm revealed the following:

Q. How do I control the PS1 prompt in a PB delegated shell?
A. You can control any environment variable from within a policy, i.e.
setenv("PS1", host +"($PWD) # ");

Hope this helps...
--donovan
"I have not failed. I've just found 10,000 ways that won't work." - Thomas Edison