1834724 Members
2462 Online
110069 Solutions
New Discussion

Re: Prompt

 
navin
Super Advisor

Prompt

I have set up my prompt to reflect my hostname and $ ,i would like to set the prompt with current working dirc like
hostname$/
hostname$/cd /sbin
hostname$/sbin
Please help to set this up.Thanks for the help .

Learning ...
8 REPLIES 8
Rodney Hills
Honored Contributor

Re: Prompt

Here is what I use-
export PS1='myhost ${PWD##*/} # '

This doesnt put the whole path in the prompt, just the last directory (I don't like real long prompt strings...)

HTH

-- Rod Hills
There be dragons...
Dave La Mar
Honored Contributor

Re: Prompt

Navin -
This is what we use -

PS1="$(hostname):\$PWD
$"

which will look like this -

bcprod:/home/dlamar
$


Best Regards,

dl
"I'm not dumb. I just have a command of thoroughly useless information."
A. Clay Stephenson
Acclaimed Contributor

Re: Prompt

In your .profile:

PS1=`hostname`':${PWD}>'
export PS1

NOTE: Depending upon your font, the backticks may be indistinguishable from the single quote. The backticks surround the hostname command and the sigle quotes surround the remainder. I did make yours a bit more readable with ':' and '>' but you can remove those if you like.
If it ain't broke, I can fix that.
Michael Tully
Honored Contributor

Re: Prompt

Here is my rendition:

PS1="$LOGNAME@`uname -n`:"'$PWD'" ! $ "
export PS1

Regards
Michael
"When I have trouble spelling, it's called fat finger syndrome"
Anyone for a Mutiny ?
Bill Hassell
Honored Contributor

Re: Prompt

As mentioned, the current pwd may get pretty long but just the basename may look the same (like bin in /usr/local/bin and /usr/contrib/bin) so here is PS1 with the last 2 directories:

PS1='$LOGNAME ${PWD##${PWD%/*/*}/} '


Bill Hassell, sysadmin
Geoff Wild
Honored Contributor

Re: Prompt

Here's what I add to root .profile (the logging is cool - as it keeps a history of all admins who su to root):

# Set up logging
HISTFILE=${HOME}/.sh_history_`who am i|awk '{ print $1}'`
date >>$HISTFILE
export HISTFILE
HISTSIZE=500
export HISTSIZE

# Set up shell environment:

HOST=`uname -n`
PS1="\$HOST:\$LOGNAME:\$PWD # ";export PS1
stty erase ^H


Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
navin
Super Advisor

Re: Prompt

All your replies are really helpful,it worked.Thank you very much.
Learning ...
twang
Honored Contributor

Re: Prompt

we use in profile:
export PS1="$LOGNAME@`hostname`$ "