Operating System - HP-UX
1833995 Members
3293 Online
110063 Solutions
New Discussion

Posix shell : login name in prompt

 
BORTZMEYER
Occasional Advisor

Posix shell : login name in prompt

Hi !
I wants 2 display my login name in the Posix shell prompt :

jack$ id -un
jack
jack$ su joe
joe$ exit
jack$

With Solaris, AIX, Dynix/ptx, Linux (with korn shell, bash has \u), it can b done with :

export ENV=$HOME/.shrc

in $HOME/.shrc :
export PS1=`id -un`"$ "

With HP-UX, as mentioned in su(1), the ENV environment variable is removed. So it can't work !

Any workaround ?
Pauca, sed bona.
8 REPLIES 8
Christian Gebhardt
Honored Contributor

Re: Posix shell : login name in prompt

Hi
Try this in your ~/.profile
export PS1="[$(whoami)] $(hostname):\$PWD\> "

Chris
T G Manikandan
Honored Contributor

Re: Posix shell : login name in prompt

Try this in your .profile

PS1=`hostname`"@"`logname`"#"


Thanks
harry d brown jr
Honored Contributor

Re: Posix shell : login name in prompt


Why not

whoami

??

or

echo $LOGNAME

?? which works with hpux, aix, and solaris.

live free or die
harry
Live Free or Die
BORTZMEYER
Occasional Advisor

Re: Posix shell : login name in prompt

1. See my example : i want PS1 changes after su.
Your solutions don't work.
2. whoami is equivalent 2 id -un but doesn't exist on Dynix/ptx.
3. With Solaris, AIX, etc., su does'nt unset $ENV, so $HOME/.shrc is source and PS1 is assigned properly (i.d. id -un is executed)
Pauca, sed bona.
T G Manikandan
Honored Contributor

Re: Posix shell : login name in prompt

How about using this

PS1=`/usr/xpg4/bin/id -un`"$"


Thanks
BORTZMEYER
Occasional Advisor

Re: Posix shell : login name in prompt

T.G., i can't find /usr/xpg4/bin/id
i'm on HP-UX 11.0
but it doesn't matter : your solution seems not to work.

To reflect login name in PS1, i think it can't be done in .profile because .profile ISN'T reread after su. Only the script mentioned with $ENV is reread, but su/HP-UX unset it !!!

Any idea ?

Cyril.
Pauca, sed bona.
Christian Gebhardt
Honored Contributor

Re: Posix shell : login name in prompt

Hi
it is right that "su " doesn't read .profile but "su - " does.

You can write this lines in /etc/profile than every user has the new prompt (even after a "su " )

Chris
BORTZMEYER
Occasional Advisor

Re: Posix shell : login name in prompt

Chris,
/etc/profile isn't read after su just "su -"
i want my prompt changes everytime i do a su (not only a "su -") like in my example.

Pauca, sed bona.