Getting UNIX prompt to display current directory

Doug Gwyn gwyn at smoke.BRL.MIL
Sun Mar 19 16:47:07 AEST 1989


In article <5582 at ncsugn.ncsu.edu> fristens at ncsugn.ncsu.edu (Brian Fristensky) writes:
>In MS-DOS there is a very easy way to get the current directory displayed as
>part of the prompt  (prompt $p).  In UNIX, there is certainly no
>straightforward way to do this.

False.

>My guess is that it would involve getting pwd output into the shell variable
>$PS1, but that would require somehow getting pwd to execute after each
>command you type. 

False.

This question arises every six months or so.  If your shell supports
functions or aliases, then you can replace the "cd" command with one
that not only chdirs but also sets $PS1 or $prompt (depending on the
type of shell).  If your shell supports evaluation of the prompt
string, then there is an obvious way to accomplish what you want.
Finally, if you have nothing but incredibly puny shells, you can set
a trap in your interactive shell that modifies the prompt string
when a signal is sent by a "cd"-like executable binary or shell script.
Depending on the shell, you may have to use some command other than
"cd" when changing working directories in order for the kludgery to
work.



More information about the Comp.unix.questions mailing list