We help IT Professionals succeed at work.

Displaying full path in prompt

420lou
420lou asked
on
This seems like it should be a simple thing to do, but I can't figure out how to display the full current path in the prompt. Using "set prompt="'pwd' " only displays the path of the login directory and never changes. Is there any way that I can have the prompt dynamically display the CURRENT path?
Comment
Watch Question

CERTIFIED EXPERT

Commented:
#if you use csh you need to make an alias like:
   alias mycd '\cd \!$; set prompt = "`pwd`% "'
#if you have tcsh
set prompt = "%B%C2%B\% "
CERTIFIED EXPERT
Commented:
Hi 420lou,

     For ksh and bash, put the followings in you .profile
   
    HOSTNAME=$(hostname)
    PWD=$(pwd)
    PS1='${LOGNAME}@${HOSTNAME}[${PWD}] !# '

    export HOSTNAME PWD PS1
    ( take the HOSTNAME and LOGNAME out if you don't like it)


     For c/tcsh shell, put the followings in your .cshrc file:

     setenv HOSTNAME `hostname`
     set prompt="${LOGNAME}@%m %~ %! > "

    You can change the prompt char to something else if you don't like
"#" or ">"

KongAWS Certified Solutions Architect - Professional
CERTIFIED EXPERT

Commented:
yuzh's comments work, but how about good old:

export PS1="\$PWD> "

=)
CERTIFIED EXPERT

Commented:
yuzh, %~, %m etc. does not work for csh (as I already said)
CERTIFIED EXPERT

Commented:
Hi  ahoffmann ,

    You are right,  %~, %m etc. does not work for csh on my system, it only work for tcsh.

    But the following will work for csh ( I tested it on Solaris 6/7/8)

     setenv HOSTNAME `hostname`
     set prompt="${LOGNAME}@${HOSTNAME}${PWD} >"

     
CERTIFIED EXPERT

Commented:
> set prompt="${LOGNAME}@${HOSTNAME}${PWD} >"

NO. Except you have a very special csh, then please tell me, I'm interested in: OS, version, etc.
CERTIFIED EXPERT

Commented:
Hi ahoffmann,

   As what I said above, I am using Solaris 5/7/8 (For SPARC SunOS 5.X).

   
CERTIFIED EXPERT

Commented:
NO, deliverd csh with Solaris 5/6 cannot do it as described. Dot.
Yuzh, did you probably have csh linked to tcsh?
Or stupid question: did you try a cd after the setenv?

Author

Commented:
yuzh,
  the  %~  was really all I was looking for, but you nailed it. Would you happen to know what the code is for a line break. %_ or something of the sort (I'm thinking too DOS here). Actually, do you know where I can just find a full reference of all the usable codes and variable values? I've looked all over the place and came up with next to nothing. Thanks man.

Author

Commented:
I'm going for:

<~/CURRENT_PATH>
# coomand_goes_here

you know... in case you were wondering...
CERTIFIED EXPERT

Commented:
Hi ahoffmann ,

   I just verify the csh on with Soalris 5 and 7
  set prompt="${LOGNAME}@${HOSTNAME}${PWD} >"

   doesn't work. the prompt does not change after cd !

    It only work for tcsh !

    Thanks.
KongAWS Certified Solutions Architect - Professional
CERTIFIED EXPERT

Commented:
<~/CURRENT_PATH>
# coomand_goes_here

Ok, you're not using ksh, but here's the ksh equiv to your question:

export PS1=\$PWD'
> '

Yes, extend it to two lines and take it literally...

CERTIFIED EXPERT

Commented:
420lou, already thought about this problem (path too long as prompt), but didn't mention it.
How about using your terminals titlebar for the path, and leaving the prompt as is?
But this needs an alias in all shells.
Which shell are you using, tcsh?
CERTIFIED EXPERT

Commented:
Hi 420lou ,

   Now, I get back to you question. If you want to know the reference setting for promt. you can use "man" to find out the settings for your shell.

   eg.  for tcsh shell,  do:
          man tcsh
         for ksh,   man ksh etc.
         
CERTIFIED EXPERT

Commented:
No comment has been added lately, so it's time to clean up this Topic Area.
I will leave a recommendation for this question in the Cleanup topic area as follows:

- Answered by yuzh

Please leave any comments here within the next 7 days

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER !

tfewster
Cleanup Volunteer
CERTIFIED EXPERT

Commented:
so we agree that %~ (and %m) is the accepted answer
CERTIFIED EXPERT

Commented:
ahoffmann, 420lou said on 09/24/2001 06:22PM PST that it worked for him, so I guess he must be using tcsh. But I don't understand why he didn't accept your first comment as an answer.

On the other hand, you answered his second question. And I'd like to use this thread for a FAQ on setting the prompt, so I'll post a "points for ahoffmann" question.
Answered by yuzh (original recommendation)

SpideyMod
Community Support Moderator @Experts Exchange
CERTIFIED EXPERT

Commented:

Explore More ContentExplore courses, solutions, and other research materials related to this topic.