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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to put pathname into prompt ?

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
0
0
DE
Hi folks,

I'd like to create a prompt on our Sun machines that shows the current path the user is in...

Under AIX we did something like:

readonly LOGNAME
export LOGNAME
case LOGNAME in

root) PS1='<root> $PWD # ';;


But as soon as I login I get:

<root> $PWD #

Instead of

<root> / #

as desired...

Looks like Sun is not familiar either with $PWD or with $PWD surrounded by ' '

What's wrong here?
Any ideas what the differences are between AIX and Sun in this case ?

Thanks in advance !

Regards
Thomas
 
Hi,

With Korn shell, try

export PS1=&quot;<root> \$PWD #&quot;

It depends on the shell you use
 
Add this line in your .profile :

export PS1=&quot;[$(hostname)]\$PWD> &quot;

Re-execute your .profile
. /.profile

And the prompt might be like :
[myserversun]/myhomedir/mydir1>

This tips works in Kron shell (ksh).
I hope i can help you,
Regards.

 
Hi folks,

it's not working ...

I always get output

$PWD

instead of the current path I'm in ...

Could it be there's no ksh being used ?
How can I determine and change that ?

Regards
Thomas
 
Thomas, do an echo $SHELL, or grep <username> /etc/passwd to determine your shell. It's probably bourne shell (sh) if you're using the default, and this doesn't recognise PS1 as far as I know. To use the ksh shell, just type ksh at the prompt. You should then be able to set PS1 to whatever you like as above. Some people change root's default shell to ksh, but this isn't recommended for recovery purposes in the event of losing the /usr filesystem. HTH.
 
You must execute your .profile or your command

Edit your etc/passwd file and define the default shell with ksh :

youruser:x:uid:gid:comment:/home/youruser:/bin/ksh

Or you can define ksh shell in your .profile user script like this :
export SHELL=/usr/bin/ksh
export EDITOR=/usr/bin/vi
export PS1=&quot;($(hostname)-$LOGNAME)\\n\$PWD: &quot;

 
With sh, suggestion:

cd ()
{
chdir $*
PS1=&quot;`who am i | awk '{ print $1 }'`@`hostname`-`pwd`# &quot;
}

So each time you use cd to change directory, it evaluates PS1...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top