Operating System - HP-UX
1821062 Members
2632 Online
109631 Solutions
New Discussion юеВ

Setting prompt to show current directory

 
Frank,Hong
Occasional Advisor

Setting prompt to show current directory

Dear all:
How can I show the current directory beside the prompt?
Should I modify the setting file?How?
Thanks anyway!
13 REPLIES 13
Muthukumar_5
Honored Contributor

Re: Setting prompt to show current directory

You can set it as simply as,

-- /etc/profile --

export PS1='$PWD # '

hth.
Easy to suggest when don't know about the problem!
Slawomir Gora
Honored Contributor

Re: Setting prompt to show current directory

HI,
you can add to .profile

export PS1=`hostname`":"'$PWD'"# "
RAC_1
Honored Contributor

Re: Setting prompt to show current directory

echo $PWD
command-pwd
There is no substitute to HARDWORK
Muthukumar_5
Honored Contributor

Re: Setting prompt to show current directory

If you want temporarily then in shell prompt execute as,

# export PS1='$PWD # '

else user specific then,

put it in $HOME/.profile file.

hth.
Easy to suggest when don't know about the problem!
Yogeeraj_1
Honored Contributor

Re: Setting prompt to show current directory

hi,


we use:
export PS1='K250: ${PWD##/}>'

where my server name is K250

of course, you will have to add the above line in your .profile

hope this helps too!

kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Muthukumar_5
Honored Contributor

Re: Setting prompt to show current directory

Yogee,

Hope you are great there :)

export PS1='K250: ${PWD##/}>'

You don't want / in pwd ?

Instead you can use as,

export PS1='`hostname`: ${PWD}>' itself. It will help you when changing hostname.

thx.
Easy to suggest when don't know about the problem!
Shweta_3
Occasional Advisor

Re: Setting prompt to show current directory

Hi Frank,

If you are using ksh/bash, you can place the following in the .profile file.
And source the file ". ~/.profile"

The " $' " in the next line is deliberate to get a clean line to type your command, especially if you are deep down your directory!!

export PS1='[$LOGNAME@'`hostname`':$PWD]
$'

Enjoy!!
Ranjith_5
Honored Contributor

Re: Setting prompt to show current directory

Hi,

Add the following entry in /etc/profile

or $HOME/.profile


export PS1="`whoami`@`uname -n` in \$PWD>#"


regards,
Syam
Steve Lewis
Honored Contributor

Re: Setting prompt to show current directory

If you use X windows then you can also set the same details as your window title. Just add this to the end of your ~/.profile ( the ^M is a CTRL-M, got by typing CTRL-V, then CTRL-M, it is not ^ then M.)


function settitle
{
case $TERM in
xterm|dtterm)
echo "\033]0;$1\007\c"
;;
hp*)
echo "\033&f0k${#1}D$1\c"
;;
*)
;;
esac
}
PS1=$(settitle '[$LOGNAME]'`hostname`:'${PWD}')^M'[$LOGNAME]'`hostname`':${PWD}> '
Andy Torres
Trusted Contributor

Re: Setting prompt to show current directory

My favorite prompt in POSIX shell:

========= In my .profile =========
export PS1='
$LOGNAME@$HOST: [$PWD] \

# '
=============================

Gives me present working directory in a "header" line, then drops a line to give me full use of the entire length of the command line.

Hope that helps.
Andy Torres
Trusted Contributor

Re: Setting prompt to show current directory

Oops. I forgot to mention I export the HOST variable as well:

==========================
export HOST=`/usr/bin/hostname`
==========================
Geoff Wild
Honored Contributor

Re: Setting prompt to show current directory

Here's how I do it in .profile:

HOST=`uname -n`
PS1="
\$LOGNAME@\$HOST [ \$PWD ]
# ";export PS1


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.
Rodney Hills
Honored Contributor

Re: Setting prompt to show current directory

I like to highlight the prompt and only display the last directory name of the PWD path (sometimes the path can get quite long).

Here is what I have in my .profile-

export ttybold=`tput bold` ; export ttynorm=`tput rmso`
export PS1='${ttybold}pegasus ${PWD##*/} #${ttynorm} '

HTH

-- Rod Hills
There be dragons...