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!

Changing the User Command Line

Status
Not open for further replies.

MagnumVP

IS-IT--Management
Jul 9, 2002
109
US
I want to know if it is possible to change the default command line ($) to possible show me the current working directory.

Example;

Currently my command looks like,

login: MagnumVP
Password:
$pwd
/export/home/MagnumVP
$

I want the $ to be changed to the results of the pwd. That will change which ever the working directory I'm in.

Is this even possible?

Thanks

MagnumVP
 
I'm assuming you are using a Korn Shell (based off previous posts)

PS1='[$PWD]'

 
To include your hostname too, you could also use:

PS1=""`hostname`":"'$PWD'"""# "
export PS1

Put this in your .profile (in your home directory) to activate it every time you log in. HTH.
 
Ken !

I have tried your script on my root .profile:

PS1=""`hostname`":"'$PWD'"""# "
export PS1


... and it seems to work only halfway, I get:

sunlab:/#

... I looked at my environment and $PWD, is set to "/"
and that was the caused, but why is $PWD=/ ?

any clue ?

also your tick mark for your script "'$PWD'", is that the
same tick mark as "`hostname`" (where is that on the key board)?


 
Hi - sorry, I should have explained that the backtick character can be found above the tab key, next to the number 1. I assume you're logging in as root, in which case your intial password will be /, ie your home directory. Try changing directory and see how it responds. Your prompt looks fine to me (assuming your hostname is sunlab?). Hope this clarifies things.
 
It can be done in csh using aliases so it should be possible in ksh. I keep meaning to try but never get around to it. Here's the csh version:

set user = `whoami`
set host = `hostname`;
set dir = ~$user;
set home = $dir
alias setd 'set noglob ; set dir=`dirs`; set dir=$dir[1]; unset noglob'
alias setp 'setd ; set prompt = "\! $user@$host ($dir) % "'
alias cd "cd \!* ; setp"
alias pushd "pushd \!* ; setp"
alias popd "popd ; setp"
setp
 
Oops - sorry just read your last post and realised it refers to the tick marks around PWD. These are just plain apostrophes ('), not backticks. Cheers.
 
Hi,

my contribution is just for the sake of readability.

You don't have to use so many quotes.

in your .profile you can add:

HOSTNAME=`/usr/bin/hostname`
PS1='$HOSTNAME:$PWD> '

mrjazz [pc2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top