Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to change su prompt # to

Status
Not open for further replies.

mingx98

Technical User
Mar 16, 2000
78
CA
In b shell,when su to root,the prompt is
#, but my boss need it be hostname#,
I had to export PS1=`hostname`#, but they need
when su root ,The prompt is `hostname`# sutomstically,
how can I do this ?
Thanks
 
When you use su it works in two ways: -

su root will maintain your current environment variables
su - root will assign the root environment variables.

If you are running bourne shell then in order to assign your new prompt on each login you need to set PS1 in the .profile file in the home directory. i.e. /.profile.
 
Hi Mingx98, the following one-liner will solve your problem.
PS1="`hostname`#" ; export PS1
OR
you can customize it further to include some goodies such as user's ID, date, and any special character that worth dying for. e.g.

PS1="$LOGNAME@`hostname`:`date +%m%d%y`:#" ; export PS1

Add the above to your /etc/profile for universal/permanent implementation, or to a particular user's $HOME/.profile
FYI. if the user(s) logs in via the console, then it might be necessary to also add it to the /.dtprofile or $HOME/.dtprofile ^^^^^^^^^^^^^^^^
None is Better!
^^^^^^^^^^^^^^^^
bkonline@comcast.net
 
I use a custom root prompt by defining an 'su' macro which actually runs:

[tt]su - root -c 'PS1=myprompt /bin/ksh'[/tt]

(It's actually a little more complex because it behaves differently if I provide different parameters to su). Annihilannic.
 
hi there any idea what the PS1 line should look like if i wanted the userid of the person to change after i did an SU? thanks
 
Can you clarify what exactly you want it to do? Perhaps type in an example of the su commands and what you want the prompts to look like? Annihilannic.
 
yep i think $logname will do it. thanks - sorry for the short details.
TA!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top